0
\$\begingroup\$

I have a radius and the 2 angles for northSouth and eastWest rotations in degrees. I need a Spherical position or a cartesian position (I have code translate one to the other)

Where a position is defined as one of the following ...

class Vector {
  public float x; // distance along x axis
  public float y; // distance along y axis
  public float z; // distance along z axis
}

class SphericalPosition {
   public float radius;       // distance from center
   public float azimuth;      // distance from 0 degrees around polar axis
   public float inclination;  // distance up from equator (x,z plane)
}

I am looking for an implementation to one of the following 2 methods ...

SphericalPosition FromAngles(float radius, float degreesUpDown, float degreesRound)
{ 

}

Vector FromAngles(float radius, float degreesUpDown, float degreesRound)
{

}

EDIT: Maybe someone can confirm or deny this but given a radius and 2 angles I believe this is referred to as a polar coordinate?

So in that light I guess i'm asking how to convert from a polar coordinate defined as the following ....

class PolarPos
{
   public float radius;         // distance from center
   public float AngleUpDown;    // rotation of x,z plane
   public float AngleLeftRight; // rotation round y axis
}

... in to one of the above

EDIT 2: Ah ha ok it looks like what I have are the radius and ...

orbital / inclination angle (in degrees): http://en.wikipedia.org/wiki/Orbital_inclination

and the polar / azimuth angle (in degrees): http://en.wikipedia.org/wiki/Azimuth

And essentially I think I need the math to turn degrees in to longitude / latitude type coords (the spherical position as defined above).

\$\endgroup\$
6
  • \$\begingroup\$ Are you asking how you convert Geographic coordinates to Cartesian coordinates? \$\endgroup\$
    – Casey
    Mar 1, 2015 at 15:28
  • \$\begingroup\$ not exactly ... i have the radius and an angle on 2 axis and I want either a cartesian or a spherical position, if I had one I could convert to the other but I have neither. \$\endgroup\$
    – War
    Mar 1, 2015 at 15:53
  • \$\begingroup\$ How is this question not trivially addressed by Googling "Azimuthal Coordinates", yielding: en.wikipedia.org/wiki/… \$\endgroup\$ Mar 1, 2015 at 16:04
  • \$\begingroup\$ Maybe its my understanding of these coordinate systems that is wrong ? is a spherical positions azimuth and inclination values distances or angles? I think they are distances and its the angles I have. \$\endgroup\$
    – War
    Mar 1, 2015 at 16:09
  • \$\begingroup\$ Regardless whether you are needing polar or spherical coordinates, you need 2 angles and one distance (for 3D, at least. 2D only requires one angle) \$\endgroup\$
    – Casey
    Mar 1, 2015 at 16:12

1 Answer 1

0
\$\begingroup\$

I was having this issue today and thought I would share what I found. Link to some Maths!

I resolved this code into the following C# code, making note that my up axis is Y:

private Vector3 getPosition(float hAngle, float vAngle, float distance)
{
    Vector3 result = new Vector3();
    result.x = (Mathf.Sin(hAngle * Mathf.Deg2Rad) * Mathf.Cos(vAngle * Mathf.Deg2Rad)) * distance;
    result.z = (Mathf.Cos(hAngle * Mathf.Deg2Rad) * Mathf.Cos(vAngle * Mathf.Deg2Rad)) * distance;
    result.y = (Mathf.Sin(vAngle * Mathf.Deg2Rad)) * distance;
    return result;
}

Is it the best solution? no idea but it works for me :) hAngle is the horizontal angle around the Y axis, and that * Mathf.Deg2Rad is converting the Euler angle into a Radian.

Hope this helps someone.

\$\endgroup\$

You must log in to answer this question.

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