point perpendicular to a vector question

Started by
2 comments, last by janta 14 years, 8 months ago
Hi, I have a linesegment 'v' and I want to find a point that is at an 'r' distance to v and perpendicular to v(from the starting point of the line segment).Its in 2d so there will be two points on either side of the line.This can be one by solving 2 equations,one by testing dot product and other equation through distanace.Is there an efficient implementation for it???Thanks in advance. Thanks & Regards, brett.
Advertisement
vector2 perp(-v.y, v.x);perp = normalize(perp) * r;vector2 point1 = start_point + perp;vector2 point2 = start_point - perp;
Is that what you're looking for?
Quote:Original post by jyk
vector2 perp(-v.y, v.x);perp = normalize(perp) * r;vector2 point1 = start_point + perp;vector2 point2 = start_point - perp;
Is that what you're looking for?


Ya thank you very much.But why is (-v.y, v.x) taken??
Because 2 perpendicular vectors have a dot product equal to 0
And the dot product v1.v2 = v1.x * v2.x + v1.y * v2.y

so if v2.x = -v1.y and v2.y = v1.x,
v1.v2 = v1.x * -v1.y + v1.y * v1.x = 0

You could also take v2.x = v1.y and v2.y = -v1.x (which is the opposed vector)
This is how the previous poster gets to two distinct solutions (start_point + perp and start_point - perp)

This topic is closed to new replies.

Advertisement