Given a line defined as two points in screen coordinate space (which themselves are two 2D vector positions) how would I calculate a 2D Vector perpendicular in the "up" direction for determining a normal force?
Tell me more
×
Game Development Stack Exchange is a question and answer site for
professional and independent game developers. It's 100% free, no registration required.
|
|
If you have a vector v = A - B (the direction is from B to A), then you need to find a vector u so that dot(u,v) = 0. If v=(x,y), there's no unique solution for this problem, but let's choose the normal pointing to the left side of the v vector. This one is u=(-y,x) and it is attained by rotating v by 90 degrees. Using complex numbers: v = x + i y and a rotation of 90 degrees means multiplying v by i. Hence u= vi = i x - y or in cartesian coordinates: u=(-y,x). |
|||
|
|