Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimal perpendicular vector between a point and a line

Tags:

vector

Okay so I'm trying to get a separating axis theorem algorithm to work (for collision detection) and I need to find the minimal perpendicular vector between a point and a line. I'm not asking for the minimum perpendicular distance (which I know how to find) but rather the vector that would have the same magnitude as that distance and that goes from an arbitrary point and a point on the line. I know the location of the point, a point on the line, and a unit vector giving the direction of the line.

What I tried doing was first finding the minimal distance between the point and the line.

The next part is confusing but I: 1) Found the vector between the point and the point on the line I know 2) Found the vector between the point on the line and the point on the line plus the unit vector giving the direction of the line 3) Took the cross product of these two vectors (I'll call this cross product A) 4) Took the cross product of the unit vector giving the direction of the line and the vector from cross product A (I'll call this cross product B) 5) Normalized cross product B 6) Scaled cross product B by the minimal distance

Anyways that whole attempt failed miserably. Can anyone tell me how I am supposed to find this vector?

like image 302
user421215 Avatar asked Mar 08 '11 01:03

user421215


2 Answers

If I understood your question correctly, I believe this is what you're looking for:

P - point
D - direction of line (unit length)
A - point in line

X - base of the perpendicular line

    P
   /|
  / |
 /  v
A---X----->D

(P-A).D == |X-A|

X == A + ((P-A).D)D
Desired perpendicular: X-P

where the period represents the dot product and |X-A| means magnitude.

like image 65
Pablo Avatar answered Oct 08 '22 17:10

Pablo


enter image description here

From the above figure, you have:

q = p + s --> s = q - p = q - (p2-p1) = q + p1 - p2

==> s^ = |q - p2 - p1| / |s|   (unitary vector)

Also:   |s| = |q| sin c = |q|sin(b-a)

b = arcsin (qy / |q|); a = arcsin( p1y / |p1| )

where: |q| = (qx^2 + qy^2)^1/2
like image 28
ArBR Avatar answered Oct 08 '22 18:10

ArBR