# 3D rays

1. Nov 21, 2008

### cam875

Im having problems understanding headings for 3d rays. I mean with 2D you can have an object at (2,3) with a heading of 83 degrees. But in 3d you can have an object at (2,3,3) but how can you describe its heading, do you need two separate headings for the two planes, how does this work. Thanks in advance

2. Nov 21, 2008

You can describe a direction in 3D with two angles θ and ϕ, with θ being the angle from the z-axis, and ϕ being an angle in the xy-plane. You can think of them as corresponding to latitude and longitude, which specify a location on a sphere, or equivalently a ray from the centre to a point on the sphere.

Together with a third coordinate r representing distance, you get the spherical coordinate system (r, θ, ϕ), which picks out a point in space just like the Cartesian (x, y, z) coordinate system.

3. Nov 21, 2008

### cam875

so if you have an object at (0,0,0) and its heading on the z plane is 0 degrees and on the x-y plane it is 0 degrees and the object travels 1m in that direction how do you figure out its new x,y,z co-ord. If you think about it the object would travel straight up but how can you prove this?

4. Nov 21, 2008

I'm not quite sure what you mean by the "z plane"; do you mean that its heading is at an angle of 0 degrees to the z-axis? In that case there are at least two ways you could approach the problem.

If your displacement vector is d, then if its angle to the z-axis is 0 (i.e. it is parallel to the z-axis), you have ‖d‖ = d · k = dz (where k is your unit vector in the z-axis), so if ‖d‖ = 1, you must have d = (0, 0, 1).

A second, more straightforward method is this: You know that your displacement vector in spherical coordinates is (r, θ, ϕ) = (1, 0, 0). Then you could transform from spherical coordinates to Cartesian coordinates:
x = r sin θ cos ϕ
y = r sin θ sin ϕ
z = r cos θ​
from which you would get x = 0, y = 0, and z = 1.

5. Nov 21, 2008

### HallsofIvy

Staff Emeritus
Another way is to use the "direction angles", the angles the vector makes with with each of the axes, say $\theta_x$, $\theta_y$, $\theta_z$. Of course there are three angles when, as said above[, you need only two, so those are not independent: for any vector, $cos^2(\theta_x)+ cos^2(\theta_y)+ cos^2(\theta_z)= 1$ so the components of a unit vector are just its "direction cosines".

6. Nov 21, 2008

### cam875

ok, starting to make sense but how exactly did you figure out

x = r sin θ cos ϕ
y = r sin θ sin ϕ
z = r cos θ

because x = 0, y = 0, and z = 1 is the exact answer and I want to know your method you used to figure out those formulas, and do you have to use trig?

also, i have a question related to 2d math. If you consider a similar problem where an object lies at (0,0) and has a heading of 45 degrees and its distance is 1 than the new x,y co-ord should be (0.5,0.5) right? but when you do the trig it gives you (0.707,0.707) which one is right?

7. Nov 21, 2008

You can derive the relations for spherical coordinates using some trigonometry. Wikipedia has them but unfortunately doesn't show a derivation; here's a rough sketch of how it works:

Let's say you have a vector r specified in spherical coordinates by (r, θ, ϕ), where r is the length, θ is the angle to the z-axis, and ϕ is the angle you get in the xy-plane by projecting r onto the xy-plane. (See the first figure on the Wikipedia article for an idea of what this looks like.) The dotted triangle has three sides: the vector r itself, the vertical side which has length z, and the bottom side being a vector that we'll call, say, r', with length r'. Trigonometry gives z = r cos θ and r' = r sin θ. Now this r' vector is entirely in the xy-plane, and its x and y components are the same as those of r, so you end up with x = r' cos ϕ and y = r' sin ϕ. Putting r' = r sin θ gives the result.

For your second question, (0.707, 0.707) is correct. If you check the length of (0.5, 0.5), you get about 0.707 by the Pythagorean theorem, not 1.

8. Nov 22, 2008

### cam875

so your saying that if you travelled 1 metre on a 45 degree angle you would travel 0.5 m on the x axis and the y axis or 0.707 m on the x and y axis because 0.5 m makes much more sense.

9. Nov 22, 2008

It would be 0.707 m.

If you move in a straight line such that your positions along the x- and y-axes each change by 0.5 m, you will have traveled 0.707 m. If you first went 0.5 m in the x direction and then 0.5 m in the y direction, then yes, the distance you traveled would be 1 m, but the displacement from the original location would only be 0.707 m (because you didn't go in a straight line).

10. Nov 22, 2008

### cam875

ok I think i understand so if an object travels 1 m on a 45 degree angle from (0,0) it is now at (0.707, 0.707)?

now im starting to wonder where did sin cos and tan come from and how do they actually work in 2D cuz i dont really just like using them without understanding them.

11. Nov 23, 2008

### HallsofIvy

Staff Emeritus
Hopefully you see that the x and y components of a vector of length 1 can't be 1/2 because of the Pythagorean theorem: (1/2)2+ (1/2)2= 1/4+ 1/4=1/2, not 1.
$$\left(\frac{\sqrt{2}}{2}\right)^2+ \left(\frac{\sqrt{2}}{2}\right)^2= \frac{2}{4}+ \frac{2}{4}$$
$$= \frac{1}{2}+ \frac{1}{2}= 1$$

As for "where sin cos and tan come from", they are DEFINED in terms of ratios of exactly the quantities you are talking about. Here's a nice little introduction:
http://www.clarku.edu/~djoyce/trig/

12. Nov 23, 2008

### cam875

alright thanks for the info, ill check that link out.

13. Nov 30, 2008

### eee3

Wha, that wikipedia-pic sure was confusing.
This one that is easier to understand, not using the same axis-system though, just rename x/y/z if you find it confusing.

The big blue dot is a point in the 3d-space. The big black dot is a point on the XZ-plane straight below the 3d-point.
Now you can easily see that it simply consists of two 2d-triangles, one blue and one red. The length of b is simply found by using trig on the blue triangle, that's why adriaks formulas for x and y have two trig-terms while z only has one:
x = r sin θ cos ϕ
y = r sin θ sin ϕ
z = r cos θ​
Note again that it's not the same coordinate system.

14. Dec 5, 2008

### cam875

ok i wrote a computer program using what i learned from here and im hoping its now correct. It tells me that if I travelled with a heading of 45 degrees on the x-y plane and 45 degrees on the z plane or w.e u wanna call it for a distance of 1 from (0,0,0) i end up at (0.707, 0.707, 0.707) im hoping that that is correct.

15. Dec 5, 2008

No, it's not; you'd get a total length of $$\sqrt{(0.707)^2+(0.707)^2+(0.707)^2} = 1.225$$ by the Pythagorean theorem. If you put in r = 1 and 45 degrees for each of the angles in the equations
x = r sin θ cos ϕ
y = r sin θ sin ϕ
z = r cos θ​
you get (0.5, 0.5, 0.707).

16. Dec 5, 2008

### cam875

that equation doesnt't make sense to me, the z part makes sense but why is there 2 different trigonometric calculations involved in the x and y part.

17. Dec 8, 2008

### eee3

Image 2 posts up ^^

The length of the hypotenuse for the XY-plane-triangle is given by [Hypotenuse for the blue plane]*Cos(phi).

So Hypotenuse_red = Hypotenuse_blue*Cos(phi)
Therefore:
x = Length_red =
= Hypotenuse_red * Cos(gamma) =
= [Hypotenuse_blue*Cos(phi)] * Cos(gamma) =
= r cos θ cos ϕ

18. Dec 8, 2008

Also, the Pythagorean Theorem has to hold as well: x2 + y2 + z2 = r2.

x2 + y2 + z2
= (r sin θ cos ϕ)2 + (r sin θ sin ϕ)2 + (r cos θ)2
= r2 sin2 θ cos2 ϕ + r2 sin2 θ sin2 ϕ + r2 cos2 θ
= r2 (sin2 θ (cos2 ϕ + sin2 ϕ) + cos2 θ)
= r2 (sin2 θ + cos2 θ)
= r2.

Also, as a general note, observe that x and y depend on both angles, so they both better be in the equations for them.