Hello folks, I googled around and I yet can't find a way to get this done.
Suppose I have a line segment going from (x1,y1,z1) to (x2,y2,z2). How do I calculate the normal vector perpendicular to this line?
Thanks for any help.
Hello folks, I googled around and I yet can't find a way to get this done.
Suppose I have a line segment going from (x1,y1,z1) to (x2,y2,z2). How do I calculate the normal vector perpendicular to this line?
Thanks for any help.
Edit: Whoops I thought you were asking a 2D question, I didn't see the z coordinate.
It's important to realize that you're asking to treat the line segment as a mathematical plane, in order to calculate the normal. This means the normal can face in one direction, or the other. An easy way to calculate the normal is to rotate the segment CCW, or rotate it CW, followed by a normalization.
CCW Example:
n = Vec2( seg.y, -seg.x );
The above comes from writing down the 2x2 rotation matrix for a 90 degree CCW rotation, where the entries of the matrix are either sin or cos of 90. When we multiply a vector with this matrix we get the above result.