I am trying to find a way to extend a line segment by a specific distance. For example if I have a line segment starting at 10,10 extending to 20,13 and I want to extend the length by by 3 how do I compute the new endpoint. I can get the length by sqrt(a^2 +b^2) in this example 10.44 so if I wanted to know the new endpoint from 10,10 with a length of 13.44 what would be computationally the fastest way? I also know the slope but don't know if that helps me any in this case.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Finding k smallest elements in a min heap - worst-
- Index of single bit in long integer (in C) [duplic
I just stumbled upon this after searching for this myself, and to give you an out-of-the-box solution, you can have a look at the code inside a standard Vector class (in any language) and cherry pick what parts you need, but I ended up using one and the code looks like this :
Good luck !
You can do it by finding unit vector of your line segment and scale it to your desired length, then translating end-point of your line segment with this vector. Assume your line segment end points are
A
andB
and you want to extend after end-pointB
(andlenAB
is length of line segment).If you already have the slope you can compute the new point:
I haven't done this in a while so take it with a grain of salt.