Formula to move N units along a slope in cartesian system, based upon an angle, which will calculate final point as an x,y location in grid

88 Views Asked by At

I need a formula which will calculate my final x,y location in a cartesian coorindate system.

First, let me set this up.

An Easy Example To Explain What I'm Looking For

Start at point 20, 20 in a cartesian system.

Next, if someone says, move 20 units along the x axis. I can easily calculate the next point as 40,20.

What I want to do is calculate the movement when I am given an angle from the start point (let's use 20,20 again) and the number of units to move.
For example, if someone says:

  1. start at 20, 20

  2. increase angle to 30 degrees

  3. move 20 units (along the slope).

How would I calculate the final x,y point?

This value is different because in this situation I will be moving x and y units?

Solution Constraints

The constraints of the solution are:

  1. Use the angle in the formula

  2. calculate a final x,y point that is N units of distance from the original point.

1

There are 1 best solutions below

3
On BEST ANSWER

Moving a distance $r$ from a point $(x_0,y_0)$ at an angle $\theta$ would put you at the ending point $$(x_0+r\cos\theta,x_0+r\sin\theta)$$ Presumably $r>0$, but the formula works for $r\leq0$ as well (moving a negative distance would move you backwards, and moving a zero distance would leave your position unchanged).

Is this what you need?

Note that the distance moved in the direction of the coordinate axes is just the projection of the "change vector" onto the coordinate axes.

If you are implementing this on a computer, be sure to measure the angle in the appropriate units for the library calls you will be using (degrees vs radians), and be sure to take into account the orientation of the axes (often the y-axis points down rather than up).