Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab code. Is vector perpendicular to plane? The plane is described by two vec

ID: 1770924 • Letter: M

Question

Matlab code.

Is vector perpendicular to plane? The plane is described by two vectors. Each vectors is A function is needed to determine if a given 3D vector is perpendicular to a plane described by a 2 x 3 matrix [x1,y1,z1; x2, y2, z2] that contains the coordinates of the starting point [xl.y1,z1] and end points [x2, y2, z2] Write a logical function isPerpendicular with three inputs: the two vectors defining the plane and the third vector that needs to be tested for being perpendicular to a plane . Example 1 >>isPerpendicular (a, b, c) ISPerpendicular = logical Example2 >>isPerpendicular (a, b, c ISPerpendicular = logical Example 3 >isPerpendicular(a, b, c) ISPerpendicular = logical

Explanation / Answer

A line is parallel to a plane, if it is perpendicular to the normal vector of the plane. Similarly,
A line is perpendicular to the plane, if it is parallel to the normal vector of the plane.

Hence, if the normal vector of the plane needs to be found:

Code for function isPerpendicular :

function output=isPerpendicular(vector1,vector2,vector3)
iv=cross((vector1(2,:)-vector1(1,:)),(vector2(2,:)-vector2(1,:)));
iline=(vector3(2,:)-vector3(1,:));
if(((iv(1)/iline(1))==(iv(2)/iline(2))) && ((iv(2)/iline(2))==(iv(3)/iline(3))))
output=1;
else if(iv==iline)
output=1;
else
output=0;
end
end
end

NOTE: Save this function file and do not run it, It will be used in the function calling program.

Code for running our function and checking the test data:

clc;clear all;close all;
a=[1 1 0;1 2 3];b=[2 1 3;-1 0 2];c=[3 -8 4;1 1 1];
logical=isPerpendicular(a,b,c);
display(logical);

NOTE: Now run the program, which calls the function saved previously and gives the result.