🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

2d math question

Started by
0 comments, last by GameDev.net 24 years, 7 months ago
Say you have an arbitrary line in 2d space with endpoints x1,y1 and x2,y2. Is there a computationally efficient way that I can calculate the endpoint of a line
of length (L) perpendicular to the line defined by endpoints x1,y1 and x2,y2.

Your help is greatly appreciated. If at all possible, can someone give me a detailed answer with example.

Advertisement
For simplicity I'm going to assume that x1, y1 is at the origin (0, 0). Then the vector defining your line segment is (x2, y2). From algebra we know that the inverse of a slope m is -1/m, and since the slope of our line is y2/x2 we know that -x2/y2 is the slope of the perpendicular line. This means that (-y2, x2) is the vector defining the perpendicular line segment.

So for a specific example, let the endpoints be (1, 1) and (2, 3). So the vector defining your line is (1, 2) (which is (2, 3) - (1, 1) btw). The vector defining the perpendicular line is then (-2, 1), so the endpoint that you are looking for is (1, 1) + (-2, 1) = (-1, 2).

I hope this helps and please try to refrain from posting the same message on multiple boards.

This topic is closed to new replies.

Advertisement