# How to calculate (x,y,z) from (0,0,0) having a distance ,say, r?

How can I determine the 3D coordinates (x,y,z) from a given distance r with origin at (0,0,0).

I know that in case of 2D (x,y),
x = r.sin(theta) and
y = r.cos(theta),
where theta is angle in degrees.

Do we have a similar formula for the 3D case?

• Look it up here: spherical coordinates Apr 10, 2017 at 13:04
• @AsafHaas link is broken Apr 10, 2017 at 13:10
• @nashynash: no, it's not. Wikipedia.
– user65203
Apr 10, 2017 at 13:10
• ok. Now it shows correctly Apr 10, 2017 at 13:13

You have spherical coordinates: \begin{align} x&=r\sin\phi\cos\theta\\ y&=r\sin\phi\sin\theta\\ z&=r\cos\phi\\ \end{align} $\phi$ and $\theta$ are the equivalent of latitude and longitude.

• Is θ between [0,360]. If so what about ϕ? Apr 10, 2017 at 13:11
• $0\le\phi\le\pi$, $0\le\theta\le2\,\pi$ (in radians.) Apr 10, 2017 at 13:15
• Thank you very much. You answer works perfect for me. Apr 10, 2017 at 13:17

The $\theta$-thing is called "parameterization". Because the distance between $(x,y)$ and $(0,0)$ in $\mathbb{R}^{2}$ (think of this as your "2D") is defined as $\sqrt{x^{2}+y^{2}}$, so you saw that we can write $(x,y)$ using only one parameter, $\theta$, given the distance, $r$. In the same token, since in $\mathbb{R}^{3}$ (think of this as your "3D") the distance between $(x,y,z)$ and $(0,0,0)$ is defined as $\sqrt{x^{2}+y^{2}+z^{2}}$, we can use what is called "spherical parameterization" to write $(x,y,z)$ in another form. In case you just want to know the intuition behind this this: note that $r = \sqrt{x^{2} + y^{2}}$ is equivalent to $r^{2} = x^{2} + y^{2}$ (does this remind you of a circle of center $(0,0)$ and radius $r$? It should!); note that $r = \sqrt{x^{2}+y^{2}+z^{2}}$ is equivalent to $r^{2} = x^{2}+y^{2}+z^{2}$, which is the Cartesian equation for a sphere of center $(0,0,0)$ and radius $r$ in $\mathbb{R}^{3}$.

• Thank you. But @Julian answer is what I am looking for. Apr 10, 2017 at 13:18
• @nashynash, no problem no worries. You can still "make it up" by upvoting :D Apr 10, 2017 at 13:19
• I tried that already but I need 2 more points to do that :( Apr 10, 2017 at 13:23

Besides spherical coordinates, you can work by normalizing an arbitrary vector.

In 2D,

$$r\frac{\vec v}{\|\vec v\|}=\left(r\frac{v_x}{\sqrt{v_x^2+v_y^2}},r\frac{v_y}{\sqrt{v_x^2+v_y^2}}\right),$$

and in 3D...

$$r\frac{\vec v}{\|\vec v\|}=\left(r\frac{v_x}{\sqrt{v_x^2+v_y^2+v_z^2}},r\frac{v_y}{\sqrt{v_x^2+v_y^2+v_z^2}},r\frac{v_z}{\sqrt{v_x^2+v_y^2+v_z^2}}\right).$$

• Thank you. But @Julian answer is what I am looking for. Apr 10, 2017 at 13:18