Polar Coordinates
Hi,
Can someone tell me the formulas for cartesian->polar and polar->cartesian formulas?
I''ve been doing some camera work in 3D, and it seems that polar coordinates are the best way for me to represent the camera, but I need to convert them so that D3D can use it...
I''ve got the 2D version:
x = rCos(Theta)
y = rSin(Theta)
and back again...
but I really haven''t been able to find the 3D formula''s in any of my usual research locations
thanks in advance,
Jack;
From an old project of mine:
theta = (theta/180) * pi;
phi = (phi/180) * pi;
xcoord = radius * sin(theta) * cos(phi);
ycoord = radius * sin(theta) * sin(phi);
zcoord = radius * cos(theta);
You might need to switch them round a bit depending on your definitions of phi and theta.
- seb
theta = (theta/180) * pi;
phi = (phi/180) * pi;
xcoord = radius * sin(theta) * cos(phi);
ycoord = radius * sin(theta) * sin(phi);
zcoord = radius * cos(theta);
You might need to switch them round a bit depending on your definitions of phi and theta.
- seb
The theta and phi are switched. There is a convention and to avoid confusion it is generally best to follow it. You have three values on the left and three on the right and six ways you could combine them. You can also get 24 by switching from counter-clockwise to clockwise measurement of angles. The convention is r=sqrt(x^2+y^2+z^2), theta=atan2(y, x) and phi=acos(z/r). It may seem a petty point in that all that matters is that you are consistant in how you use it within your program, but many books an articles use spherical coordinates without explaining which one is which just as many use angles without explaining they are measured counter-clockwise from the x-axis.
So:
phi = acos(z/r)
theta = atan2(x,y)
xcoord = radius * sin(phi) * cos(theta);
ycoord = radius * sin(phi) * sin(theta);
zcoord = radius * cos(phi);
and of course
r^2=x^2+y^2+z^2
Righty-ho then. Didn''t know there was a convention. This was from a vector class we had to write years ago.
- seb
phi = acos(z/r)
theta = atan2(x,y)
xcoord = radius * sin(phi) * cos(theta);
ycoord = radius * sin(phi) * sin(theta);
zcoord = radius * cos(phi);
and of course
r^2=x^2+y^2+z^2
Righty-ho then. Didn''t know there was a convention. This was from a vector class we had to write years ago.
- seb
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement