Jump to content
  • Advertisement
Sign in to follow this  
brett01

point perpendicular to a vector question

This topic is 3265 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!