   Polar/Cartesian conversion
  Hi, I'm looking for the polar->cartesian and cartesian->polar conversion formulas to use in a OpenGL-like coordinates system (+z toward the player, y up). All the formulas I've found use a z up and I'm not sure how to convert them. I need theta to be the angle with the y axis, and phi with the x axis. I suppose I could derive the polar->cartesian myself, but for the opposite I need help, so if someone knows both them I would apreciate :-)Thank you!   
  Take a look into the following link, maybe it can help you a little bit: Polar coordinate questionKimmi   ;  Thank you, but the reported equations use the z up, just as every other reference I've found elsewhere. I'm looking for the equations in the OpenGL coordinates frame (or for suggestions about how to convert them). For example, can I simply swap the y and z coordinates in the equations?In addition someone uses theta related with the 'up' vector, someone names it phi, and the precise meaning is not always explained...   ;Quote:Original post by cignox1Thank you, but the reported equations use the z up, just as every other reference I've found elsewhere. I'm looking for the equations in the OpenGL coordinates frame (or for suggestions about how to convert them). For example, can I simply swap the y and z coordinates in the equations?In addition someone uses theta related with the 'up' vector, someone names it phi, and the precise meaning is not always explained...This can indeed by confusing due to the various conventions used.One thing to keep in mind is that OpenGL doesn't really have 'a' coordinate frame, per se. If you wanted z to be up in your simulation, you could easily set up the OpenGL modelview matrix to accomodate this.As for the spherical coordinate conversion you're asking about, the basic equations can be re-arranged to allow for any axis being the 'up' axis. It can be a little confusing to work through, but if you understand what the equations are doing, it's not too hard to switch them around.For reference, here's the spherical-to-Cartesian coordinate conversion function from the CML. I stripped some stuff out to make it more readable. It's possible that in doing so I may have introduced errors, but I'm pretty sure I got it right.void spherical_to_cartesian(    float radius,    float theta,    float phi,    size_t axis, // The index of the axis that you want to be 'up'    SphericalType type, // Latitude or colatitude    vector3& v){    if (type == latitude) {   phi = constants::pi_over_2() - phi;    }    float sin_phi = std::sin(phi);    float cos_phi = std::cos(phi);    float sin_phi_r = sin_phi * radius;   size_t i = axis;    size_t j = (i + 1) % 3;    size_t k = (j + 1) % 3;    v = cos_phi * radius;    v[j] = sin_phi_r * std::cos(theta);    v[k] = sin_phi_r * std::sin(theta);}Note that even with the variable up axis accounted for, you may have to make adjustments if you consider zero degrees/radians to point down an axis other than the 'default' for that up axis.[Edited by - jyk on May 11, 2009 4:20:06 AM];Quote:One thing to keep in mind is that OpenGL doesn't really have 'a' coordinate frame, per se. If you wanted z to be up in your simulation, you could easily set up the OpenGL modelview matrix to accomodate this.That's not really an OpenGL project, its just that in my raytracer I decided to implement OpenGL 'conventions' to easily implement matrices and equations found in internet :-(Quote:As for the spherical coordinate conversion you're asking about, the basic equations can be re-arranged to allow for any axis being the 'up' axis. It can be a little confusing to work through, but if you understand what the equations are doing, it's not too hard to switch them around.Yep, I hoped to avoid learning how those transformations work and go straight to the implementation, but I fear this is the only option I have...For example, if I got it right the y variable sould be:y = r*cos(theta)I should be able to derive the others, while it could be harder to do cartesian->polar.Well, math has never been easy to me, I suppose that this will be a sane learning experience. Of course, if someone feels like providing those equations, I wont complain :-)Thank you jyk!EDIT:This is what I came with after a bit of thinking, could someone check it? I'm specifically interested in pitfalls related to the signs and the axis directions I should take into account...x = r * sin(theta) * sin(phi)y = r * cos(theta)z = r * sin(theta) * cos(phi)EDIT 2:And what about these ones for the cartesian->polar?r = len(vector);theta = acos(y / r)phi = atan2(x, z)[Edited by - cignox1 on May 11, 2009 4:39:35 AM];Cartesian = Polorx = rsin(theta)y = rsin(theta)polar = Cartesianr = x^2 + y^2tan(x/y)polor = (r,theta)   ;Quote:Original post by tnuttyCartesian = Polorx = rsin(theta)y = rsin(theta)polar = Cartesianr = x^2 + y^2tan(x/y)polor = (r,theta)It's actually spherical coordinate conversions that the OP is looking for. (Also, your formulas are wrong.)   ;  Yep, and the equations I posted *seem* to work right, except the phi one, wich I changed. I´m implementing the "Practical analytic model for daylight", and the sky seems right. As soon as I implement the 'sun' part I should be able to verify signs and axis directions...   