Use the Programming Language ---- > MATLAB <--- Calculating the vector normal to
ID: 3859125 • Letter: U
Question
Use the Programming Language ---- > MATLAB <---
Calculating the vector normal to a plane. Three points in a 3D space define a plane. A vector perpendicular to any vector lying in that plane is called a normal vector point 2 point 1 point 3 Assign planeNormal with the normal vector to the plane defined by the point1, point2, and point3. To find the normal vector, 1. A vector lying in the plane is found by subtracting the first point's coordinates from the second point. 2. A second vector lying in the plane is found by subtracting the first point's coordinates from the third point. 3. The normal vector is found by calculating the cross product of two vectors lying in the plane. Ex: If point1, point2, and point3 are [0, 0, 11.12,2,31. and [0, 3, 1] respectively, then planeNormal is [-6, 0, 61 Your Function Save C Reset MATLAB Documentation function planeNormal -getPlaneNormal ( point1, point2 , point3 ) 2 3 4 % calculate first vector in plane by subt racting the first point's % coordinates from the second point inPlanevec1 = point2 point1; 6 % Calculate second vector in plane by subtracting the first point'sExplanation / Answer
MATLAB code attached below which passes all of the above assessment tests.
function planeNormal = getPlaneNormal(point1, point2, point3)
% calculate first vector in plane by substracting the first point's
% coordinates from the second point
inPlaneVec1 = point2 - point1;
% calculate first vector in plane by substracting the first point's
% coordinates from the third point
inPlaneVec2 = point3 - point1;
% calculate vector normal to the plane by calculating the cross product
% of the two vectors lying in the plane
planeNormal = cross(inPlaneVec1,inPlaneVec2);
end
function inPlane = checkInPlane(testVector, normalVector)
% Assign inPlane with 1 if testVector lies in samplePlane, 0 otherwise.
dot_product = dot(testVector, normalVector);
if(dot_product == 0)
inPlane = 1;
else
inPlane = 0;
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.