I have two points at the end of a line.
I need to get the end coordinates of a translation of this line.
The translation will be a parallel line that is a distance d from the original line.
here is an image of what i need:
So I need a function that I can pass these two points and the distance and get the two new coordinates in returns.
I have been stuck on this problem for a while. Any help will be appreciated!
Thanks you!
The new co-ordinates will be the resulting vector of
distance d multiplied by normalized vector of which direction it's moving, added to the original vector point.
EDIT:
Given the two points of the line, you will need to calculate the normal of the vector joining these points. Information on that is here..
Normalise this vector, multiply by d, add to each point.
Calculate the vector (x2-x1,y2-y1). This is a vector in the direction of your line. A normal vector is then given by
(-(y2-y1),-(x2-x1)) = (y1-y2,x1-x2).
Divide this vector by its size to get the unit vector in the direction you want
A = (y1-y2,x1-x2)/|(y1-y2,x1-x2)|
Now given your distance d
your translated point will be given by
NewPoint = OldPoint + d * A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With