namespace EurovisionDegrees {
public static void Main (string [] args)
Console.WriteLine ("Hello World!");
testSphericToCartesian (0, 0, 0, 0, 0, 1);
testSphericToCartesian (0, 0, 0, 0, 90, 1);
testSphericToCartesian (0, 0, 0, 90, 0, 1);
testSphericToCartesian (0, 0, 0, 90, 90, 1);
testSphericToCartesian (0, 0, 0, 180, 90, 1);
testSphericToCartesian (0, 0, 0, 270, 90, 1);
testSphericToCartesian (0, 0, 0, 0, 45, 1);
testSphericToCartesian (0, 0, 0, 45, 0, 1);
testSphericToCartesian (0, 0, 0, 45, 45, 1);
testSphericToCartesian (1, 2, 3, 0, 0, 1);
testSphericToCartesian (1, 2, 3, 0, 90, 1);
testSphericToCartesian (1, 2, 3, 90, 0, 1);
testSphericToCartesian (1, 2, 3, 90, 90, 1);
testSphericToCartesian (1, 2, 3, 180, 90, 1);
testSphericToCartesian (1, 2, 3, 270, 90, 1);
testSphericToCartesian (1, 2, 3, 0, 45, 1);
testSphericToCartesian (1, 2, 3, 45, 0, 1);
testSphericToCartesian (1, 2, 3, 45, 45, 1);
static void testSphericToCartesian (float x, float y, float z, float heading, float elevation, float distance)
Vector3 ret = sphericToCartesian (x, y, z, heading, elevation, distance);
Console.WriteLine (x + "," + y + "," + z + "\thead " + heading + " elev " + elevation + " dist " + distance + "\t -> \t" + ret);
static float degToRad (float deg)
return deg / 180.0f * (float)Math.PI;
static float roundTo (float x)
return (float)Math.Round(x * 100000f) / 100000f;
static Vector3 sphericToCartesian (float x, float y, float z, float heading, float elevation, float distance)
float h = heading / 180.0f * (float)Math.PI;
float e = elevation / 180.0f * (float)Math.PI;
float xo = distance * (float)Math.Cos (h) * (float)Math.Cos (e);
float yo = distance * (float)Math.Sin (h) * (float)Math.Cos (e);
float zo = distance * (float)Math.Sin (e);
xo = (float)Math.Round ((x + xo) * 100000f) / 100000f;
yo = (float)Math.Round ((y + yo) * 100000f) / 100000f;
zo = (float)Math.Round ((z + zo) * 100000f) / 100000f;
return new Vector3 (xo, yo, zo);