Could someone point me in the right direction as to how this might be achieved? 3D math / geometry often throws me.

I'm looking for something like this (ideally in C#):

public Vector3 getCartesianFor(float elevation, float asimuth, float polar)
   return ????;

3 Answers 3



public static void SphericalToCartesian(float radius, float polar, float elevation, out Vector3 outCart){
    float a = radius * Mathf.Cos(elevation);
    outCart.x = a * Mathf.Cos(polar);
    outCart.y = radius * Mathf.Sin(elevation);
    outCart.z = a * Mathf.Sin(polar);

public static void CartesianToSpherical(Vector3 cartCoords, out float outRadius, out float outPolar, out float outElevation){
    if (cartCoords.x == 0)
        cartCoords.x = Mathf.Epsilon;
    outRadius = Mathf.Sqrt((cartCoords.x * cartCoords.x)
                    + (cartCoords.y * cartCoords.y)
                    + (cartCoords.z * cartCoords.z));
    outPolar = Mathf.Atan(cartCoords.z / cartCoords.x);
    if (cartCoords.x < 0)
        outPolar += Mathf.PI;
    outElevation = Mathf.Asin(cartCoords.y / outRadius);
  • \$\begingroup\$ Exactly what was after ... just need to figure out how to do this without the unity math libs ... any recommends on math libs for .Net ... or is this built in somewhere? I could only see these functions for doubles. \$\endgroup\$
    – War
    Aug 13, 2014 at 12:25

  • r: radial distance
  • θ: inclination
  • φ: azimuth

via Wikipedia

public Vector3 getCartesianFor(float radius, float inclination, float azimuth)
   return new Vector3(radius*Sin(inclination)*Cos(azimuth), radius*Sin(inclination)*Sin(azimuth), radius*Cos(inclination));

Spherical coordinates

  • \$\begingroup\$ You should elaborate about the meanings of the (literal) Greek in your answer. \$\endgroup\$ Aug 11, 2014 at 18:31
  • \$\begingroup\$ @SethBattin Thank you for the suggestion! The answer has been updated. \$\endgroup\$
    – MLM
    Aug 11, 2014 at 18:36
  • 2
    \$\begingroup\$ What you call inclination is probably the complement of what OP means for elevation, ie. the angle from the xy plane to the vector, not from vector to the z axis. \$\endgroup\$
    – MestreLion
    Aug 11, 2014 at 22:55

If by polar you mean the magnitude of the vector, and elevation is defined as the angle between vector and the xy plane (as the name implies), the function would be:

public Vector3 getCartesianFor(float elevation, float asimuth, float polar)
   return new Vector3(polar*Cos(elevation)*Cos(asimuth),

Note that this is very similar to MLM's answer, it all depends on how you define your elevation angle. I've also respected your function template signature, but I suggest a few changes:

  • asimuth is a typo, the correct spelling would be azimuth
  • polar usually refers to the 2D coordinate system (r, θ). The magnitude of the vector is commonly referred to as radius
  • A more conventional order would have radius as the first parameter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .