Spherical to Cartesian coord transform (Solution)
by Stephen Zepp · in Technical Issues · 05/25/2004 (6:24 pm) · 1 replies
This took me 2+ days to properly state in my own head, and then find the solution for, so I figured I'd post it here and maybe save someone else some time:
Given:
1) an origin (any coordinate system, it will be treated as 0,0,0 for this conversion)--commonly the player, but not always,
2) A fixed distance 'R', or the "tether/zoom distance"
3) An angle of declination (up the Z axis, measured down towards the xy plane along the x axis) 'a' in radians, and
4) An angle of azimuth (from the positive x axis towards the positive y axis) 'b', you can convert these coords from spherical to cartesian via:
x' = R sin(a)cos(b)
y' = R sin(a)sin(b)
z' = R cos(a)
So, who cares, right? Well, this describes the position and input/control parameters for an "orbit around the player" style camera, and once this offset is converted to cartesian coords, it is very easily applied to the player position, giving the camera position. The 3 sperical coordinates are directly applicable to various keyboard/mouse inputs, and intuitive to the user (IMO at least). Will slide quite nicely into the Advanced Camera Resource!
Given:
1) an origin (any coordinate system, it will be treated as 0,0,0 for this conversion)--commonly the player, but not always,
2) A fixed distance 'R', or the "tether/zoom distance"
3) An angle of declination (up the Z axis, measured down towards the xy plane along the x axis) 'a' in radians, and
4) An angle of azimuth (from the positive x axis towards the positive y axis) 'b', you can convert these coords from spherical to cartesian via:
x' = R sin(a)cos(b)
y' = R sin(a)sin(b)
z' = R cos(a)
So, who cares, right? Well, this describes the position and input/control parameters for an "orbit around the player" style camera, and once this offset is converted to cartesian coords, it is very easily applied to the player position, giving the camera position. The 3 sperical coordinates are directly applicable to various keyboard/mouse inputs, and intuitive to the user (IMO at least). Will slide quite nicely into the Advanced Camera Resource!
Torque Owner Desmond Fletcher
fletcher