How can I use atan2
to determine the coordinates where a segment ends, knowing the coordinates where it starts (x, y
), the angle of the segment and the length of the segment?
Can you tell me a solution it doesn't have to be only with atan2...
You have a right angled triangle and you can assume that the point A is at (x,y), this is much easier to explain with the use of some diagrams:
Now we know what the value for c is already because this is the length of the segment and we want to know the values for a and b because the final point is at (x+b, y+a)
From trigonometry we know what the relations between the angles and the ratios of the sides are
sin(theta) = opposite/hypotenuse
and cos(theta) = adjacent/hypotenuse
Substituting in the values we know we get:
sin(theta) = opposite/c
c = opposite * sin(theta)
and
cos(theta) = adjacent/b
b = adjacent * cos(theta)
We know that the end point is at (x+b, y+a)
which given the values for the edges we found is (x+adjacent * cos(theta), y+opposite * sin(theta))