I’m being quite dim – I can’t figure out what should probably be a fairly trivial trig problem.
Given cartesian coordinates (x, y, z), I would like to determine a new coordinate given a direction (x, y and z angles) and a distance to travel.
class Cartesian() {
int x = 0;
int y = 0;
int z = 0;
int move (int distance, int x_angle, int y_angle, int z_angle) {
x += distance * //some trig here
y += distance * //some trig here
z += distance * //some trig here
}
}
Ie, I want to move a given distance from the origin in a given direction, and need the coordinates of the new position.
This is actually for a JavaScript application, but I just need a bit of psuedocode to help me out.
Thanks
The way you’ve stated the problem, it seems that “direction cosines” make the most sense.
Assuming
x_angleis the angle in radians between the target direction and the Xaxis, etc.: