get point coordinates based on direction and distance (vector) get point coordinates based on direction and distance (vector) javascript javascript

get point coordinates based on direction and distance (vector)


Given L as the length of the vector and Ang the angle

x2 = x1 + Math.cos(Ang) * Ly2 = y1 + Math.sin(Ang) * L

Oops... I just noted the top to bottom orientation of the Y axis...Konstantin Levin, you will need adapt slightly because the formulas above assume a typical trigonometric coordinates system. In your case the formulas should be:

x2 = x1 + Math.cos(Ang) * L    // unchangedy2 = y1 - Math.sin(Ang) * L    // minus on the Sin

Also (what goes without saying, also goes in one says it...) the reference angle should be such that when y2 == y1 and x2 > x1, Ang should be zero, and it should increase as the second point is moved counter-clockwise around the first one.