MATLAB: How to calculate normal to a line

doit4melineMATLABnormalplotpoints

I plot a line in MATLAB using the points. Please tell me how to obtain the normal of that line? Can I get these plots in a single plot?

Best Answer

It is easier to answer, if you explain any details. At first I assume you mean 2D-lines, because for 3D-lines a normal line is not defined.
If you have a vector with the coordinates [x, y], the vectors [y, -x] and [-y, x] are orthogonal. When the line is defined by the coordinates of two points A and B, create the vector B-A at first, determine the orientation by the above simple formula, decide for one of the both vectors, and the midpoint between the points (A+B) * 0.5 might be a nice point to start from. Adjusting the length of the normal vector to either 1 or e.g. the distance norm(B-A) might be nice also.