T.Lange T.Lange - 2 months ago 6
Javascript Question

JavaScript: figure out point Y by angle and distance

In my project, I would like to draw a line from point X to point Y.

While I know the position of point X, I only know the angle and the distance of point Y.

So my problem is to get the coordinates of point Y by the angle (from point X) and the distance.

I am using JavaScript for this project and don't want to use any graphical library.

For example:

  • point X (10;20)

  • point Y (10° & 200px from point X)

It is probably pretty basic math, but I have no clue how to do it.

js> Math.cos(10*Math.PI/180) * 200 + 10
js> Math.sin(10*Math.PI/180) * 200 + 20

Y is at (207, 55).