# Given a point $(x,y,z)$ and an angle/bearing distance calculate the end point $(x,y,z)$

I'm not very mathematical but I'm working on a 3d program and for this part I simply want to draw a line.

I know the starting vector $(x,y,z)$, the length r of the line and the bearing/angle. I want to calculate the endpoint so I can draw the line.

I had a look around and I'm using the following. Let $\theta$ be the angle in radians, and let $d$ be the distance. Then the other endpoint is $(x', y', z')$, where:

$$x' = r\cos(\theta) + x$$ $$y' = y$$ (the endpoint 'height' should be the same as the start point)

$$z' = r\sin(-\theta) + z$$

is this correct?

Thanks

-

Your formulation will work for a line drawn in a plane parallel to the x-z plane, but I'm not clear why the angle in radians for $z$ is negative, where it is positive in the formulation for $x$. With $y$ measuring height ("is held constant"), then you need to be clear about what the reference axis for your angle $\theta$.

I'd suggest the following:

Given starting point $(x, y, z)$, with $r =$ length, $\theta$ = the measure of the angle (counter-clockwise rotation) with respect to the positive $x$-axis, in radians, then your endpoint $(x', y', z')$ is given by:

$$x' = r\cos\theta + x$$ $$y' = y$$ $$z' = r\sin\theta + z\;\;$$

Using graphic below, this will:

$\theta=0$: East being aligned with positive x-axis

$\theta=\frac\pi2 = 90^\circ$: South being aligned with positive z-axis

$\theta=\pi = 180^\circ$: West being aligned with negative x-axis

$\theta=\frac{3\pi}2 = 270^\circ$: North being aligned with negative z-axis

EDIT:

Using this coordinate system, with y-height, using x' and y' as formulated above, then the line with ending point $(x', y', z')$ will lie on the plane y' = y, parallel to the x-z plane (where y = 0), and if $z' = r\sin(-\theta) + z$, as you propose, it will point in the direction of the north-east quadrant (towards the quadrant with $x > 0,\; z< 0$), with $\theta$ measured with respect to the positive x-axis. On the other hand, given $x', y'$ and using $z' = r\sin\theta + z$, as I suggest, then the line directed from $(x, y, z)$ towards $(x', y', z')$ will point to the south-east quadrant, with $\theta$ measured with respect to the positive x-axis.

-
I'm not sure if I understand, would the vector always be directed south-east irrespective of r? – drunkmonkey Jan 12 '13 at 22:22
Yes, r has nothing to do with direction, only with length. The $-\theta$ in the formulation for $z$ makes line directed south east. If positive, $z = r \sin\theta + z_0$ would direct it toward the northeast, toward (positive quadrant.) – amWhy Jan 12 '13 at 22:25
Sorry, I meant theta (which should affect the direction). The angle I have is supposed to represent a bearing so for example if theta was 350 degrees, I should have a vector with direction just west of North? Thanks for your help – drunkmonkey Jan 12 '13 at 22:38
Does the graphic help at all? I'll work with you, on this. It's just a matter of being clear about the angle theta is measuring, with respect to which axis? for x′=rcosθ+x, it would seem to need to be measured with respect to the positive x-axis. A 350 degree angle, with respect to the positive x-axis, would put you just south of the positive x-axis: 350 degrees = -10 degrees. (positive x, negative z direction) – amWhy Jan 12 '13 at 23:15

If you treat $\theta$ as a bearing then your formultaion of $x′=rcos(θ)+x$, $y′=y$, $z′=rsin(−θ)+z$ will lead to:-

$\theta=0$: North being aligned with positive x-axis

$\theta=\frac\pi2$: East being aligned with negative z-axis

$\theta=\pi$: South being aligned with negative x-axis

$\theta=\frac{3\pi}2$: West being aligned with positive z-axis

Is this what you want?

-