Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created September 25, 2012 11:42
Show Gist options
  • Save satoruhiga/3781270 to your computer and use it in GitHub Desktop.
Save satoruhiga/3781270 to your computer and use it in GitHub Desktop.
cartesianToSpherical / sphericalToCartesian
ofVec3f cartesianToSpherical(const ofVec3f &v)
{
float r = v.length();
float s = acos(v.z / r);
float f = atan2(v.y, v.x);
return ofVec3f(r, s, f);
}
ofVec3f sphericalToCartesian(const ofVec3f &v)
{
ofVec3f vv;
vv.x = v.x * sin(v.y) * cos(v.z);
vv.y = v.x * sin(v.y) * sin(v.z);
vv.z = v.x * cos(v.y);
return vv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment