1
$\begingroup$

I am trying to translate theta and phi rotation in Blender to the Euler XYZ rotation about each axis. To do this I am currently using the following code: """

 def Sphere2Euclid(theta, phi):
    """
    Inputs: theta - Angle as defined in the GA
            phi - Angle as defined in the GA

    Outputs: x - The x rotation angle in Euler Angle Coordinates
             y - The y rotation angle in Euler Angle Coordinates
             z - The z rotation angle in Euler Angle Coordinates

    Description: This function will take the theta and phi angles as defined in the GA and convert them to Euler Coordinates

    Source for conversion: https://blender.stackexchange.com/questions/158377/object-rotation-with-polar-angles-python 
    """

x = math.sin(math.radians(theta)) * math.cos(math.radians(phi)) 
y = math.sin(math.radians(theta)) * math.sin(math.radians(phi))
z = math.cos(math.radians(phi))
return x, y, z

This current code doesn't seem to rotation from a global orientation as it does not produce the correct orientation for testing angles. Is my method of converting from theta and phi to XYZ wrong or am I fundamentally misunderstanding how blender handles rotation?

$\endgroup$
1
  • $\begingroup$ it should be z = math.cos(math.radians(theta)) i tested and it's correct. $\endgroup$ Apr 18, 2023 at 4:08

1 Answer 1

2
$\begingroup$

You're almost there. Your z calculation was incorrect. It should be angle $\theta\space(theta)$ instead of $\phi\space(phi)$:

z = math.cos(math.radians(theta))

Also take note you are also missing the radius, but I assume it is just a unit sphere ($r=1$) so I guess it's not a problem if excluded.

To visualize the Spherical Coordinate System, here is a drawing I made where: $$v=\theta \space (theta)$$ $$u=\phi \space (phi)$$ enter image description here

This results in:

$$x=r\sin \theta \cos \phi $$ $$y=r\sin \theta \sin \phi $$ $$z=r\cos \theta$$

I made an example where $\theta=67.5$ and $\phi=33.75$ on a unit sphere ($r=1$)

enter image description here

After executing the script and checking the console I can see that the vertex location on the euclidean plane has been calculated correctly.

enter image description here

Working script here with example:

import bpy
import math

def Sphere2Euclid(theta, phi):
    """
    Inputs: theta - Angle as defined in the GA
            phi - Angle as defined in the GA

    Outputs: x - The x rotation angle in Euler Angle Coordinates
             y - The y rotation angle in Euler Angle Coordinates
             z - The z rotation angle in Euler Angle Coordinates

    Description: This function will take the theta and phi angles as defined in the GA and convert them to Euler Coordinates

    Source for conversion: https://blender.stackexchange.com/questions/158377/object-rotation-with-polar-angles-python 
    """

    x = math.sin(math.radians(theta)) * math.cos(math.radians(phi)) 
    y = math.sin(math.radians(theta)) * math.sin(math.radians(phi))
    z = math.cos(math.radians(theta))
    
    return x, y, z

coords = Sphere2Euclid(67.5, 33.75)

print(coords)
$\endgroup$
2
  • $\begingroup$ Hello! Thank you so much for the detailed answer on this. My issue is more that I need to take theta and phi rotation angles and translate them to rotations around the x,y,z axis (the Euler angles). This seems to be coordinates, which isn't what I want as I just need to rotate the object by theta and phi. Am I overthinking this and translating theta and phi to it's respective rotations about the x,y,z axis is straight forward? I will also add, the reason phi is due to using physics notation, not math (it's annoying but in physics we flipped them for some reason.. luckily it's a non-issue) $\endgroup$
    – Jacob
    Apr 18, 2023 at 12:14
  • $\begingroup$ @Jacob hmm u should probably edit the content of your thread as it is not clear to me what you are asking for. maybe include a drawing or screenshot of what exactly u are trying to solve. $\endgroup$ Apr 18, 2023 at 13:49

You must log in to answer this question.

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