How do I translate a spherical coordinate to a Cartesian one?

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 ????;
}


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.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;
+ (cartCoords.y * cartCoords.y)
+ (cartCoords.z * cartCoords.z));
outPolar = Mathf.Atan(cartCoords.z / cartCoords.x);
if (cartCoords.x < 0)
outPolar += Mathf.PI;
}

• 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.
– War
Commented Aug 13, 2014 at 12:25

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

via Wikipedia

public Vector3 getCartesianFor(float radius, float inclination, float azimuth)
{
}


• You should elaborate about the meanings of the (literal) Greek in your answer. Commented Aug 11, 2014 at 18:31
• @SethBattin Thank you for the suggestion! The answer has been updated.
– MLM
Commented Aug 11, 2014 at 18:36
• 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. Commented 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),
polar*Cos(elevation)*Sin(asimuth),
polar*Sin(inclination));
}


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.