I've only found a few solutions searching, and they're either language-specific or too plex. I simply need to get a point n distance from another point rotated n amount. I'm using this for a project in HTML5 canvas. I know that there's a rotate function, but I'm working with paths and I don't believe that works with it. Regardless, I'd just like a formula where I could plug in x, y, distance, and direction.
I've only found a few solutions searching, and they're either language-specific or too plex. I simply need to get a point n distance from another point rotated n amount. I'm using this for a project in HTML5 canvas. I know that there's a rotate function, but I'm working with paths and I don't believe that works with it. Regardless, I'd just like a formula where I could plug in x, y, distance, and direction.
"n"
in radians or degrees?
– bcosca
Commented
Dec 16, 2010 at 4:16
newx = distance * Math.cos(direction) + x
newy = distance * Math.sin(direction) + y
By calculating the sine and cosine of the angle, you can get the point one unit away from the origin at the given rotation. Just multiply the coordinates by whatever distance you need. Cosine corresponds to X and sine corresponds to Y.
In other words: