Last active
September 1, 2015 13:10
-
-
Save agoose77/22958866365663903552 to your computer and use it in GitHub Desktop.
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
from math import acos, atan, cos, sin | |
from mathutils import Vector | |
def vect_to_polar(vect): | |
x, y, z = vect | |
r = vect.length | |
phi = acos(z / r) | |
theta = atan(y / x) | |
return r, phi, theta | |
def polar_to_vect(polar): | |
r, phi, theta = polar | |
x = r * cos(theta) * sin(phi) | |
y = r * sin(theta) * sin(phi) | |
z = r * cos(phi) | |
return Vector((x, y, z)) | |
vect = Vector((0.2, 99.9, 12.7)) | |
assert (vect - polar_to_vect(vect_to_polar(vect))).length_squared < 0.1 | |
print(vect_to_polar(vect)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment