Created
September 25, 2012 11:42
-
-
Save satoruhiga/3781270 to your computer and use it in GitHub Desktop.
cartesianToSpherical / sphericalToCartesian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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