Euler to degree calculation

Well I have been tinkering and wanted to convert euler roation to degree (from what i can access to whats shown in the translation panel).

The way I figured I can calculate this is…


from math import pi
...
eu=ob.rotation_euler
degx=((eu[0]/(pi+pi))*360.0)
degy=((eu[1]/(pi+pi))*360.0)
degz=((eu[2]/(pi+pi))*360.0)
print(degx,degy,degz)

ob is an object

Is there a better way to calculate this?

how about this?


import bpy
from math import pi
from mathutils import Vector
fac = 180/pi
o = bpy.context.active_object
oe = o.rotation_euler
oev = Vector(oe)
oevFac = fac*oev
print(oe,oevFac)

#gives 
#Euler((-1.804109811782837, -0.25291579961776733, -1.0320931673049927)) Vector((-103.36788177490234, -14.491007804870605, -59.13458251953125))

This also works (blender 2.53 beta):


import bpy
from math import degrees
...
o = bpy.context.active_object
oe = o.rotation_euler
a, b, c = map(degrees, (oe[0], oe[1], oe[2]))
print (a, b, c)

mb

Hi, learned from you …
[el for el in map(degrees,Eulerobject)]
works too!
Eulerobject =. bpy.context.active_object.rotation_euler

Nice isn’t it?

I have here some mine procs for such conversions and other math operations with eulers (no possible otherwise):

def Eu_degr(eu):  # eu in radians
    eu_x,eu_y,eu_z = eu[0],eu[1],eu[2]
    eu_x = math.degrees(eu_x)
    eu_y = math.degrees(eu_y)
    eu_z = math.degrees(eu_z)
    eu_degr = Mathutils.Euler(eu_x,eu_y,eu_z)
    return eu_degr

def Eu_rad(eu):  # eu in degrees
    eu_x,eu_y,eu_z = eu[0],eu[1],eu[2]
    eu_x = math.radians(eu_x)
    eu_y = math.radians(eu_y)
    eu_z = math.radians(eu_z)
    eu_rad = Mathutils.Euler(eu_x,eu_y,eu_z)
    return eu_rad

def Eu_add(eu1,eu2):  # eu1,eu2 in degrees
    eu_x1,eu_y1,eu_z1 = eu1[0],eu1[1],eu1[2]
    eu_x2,eu_y2,eu_z2 = eu2[0],eu2[1],eu2[2]
    eu_new = Mathutils.Euler(eu_x1+eu_x2,eu_y1+eu_y2,eu_z1+eu_z2)
    return eu_new

def Eu_sub(eu1,eu2):  # eu1,eu2 in degrees
    eu_x1,eu_y1,eu_z1 = eu1[0],eu1[1],eu1[2]
    eu_x2,eu_y2,eu_z2 = eu2[0],eu2[1],eu2[2]
    eu_new = Mathutils.Euler(eu_x1-eu_x2,eu_y1-eu_y2,eu_z1-eu_z2)
    return eu_new

def Eu_mult(eu1,c):  # eu1 in degrees; c - constant
    eu_x1,eu_y1,eu_z1 = eu1[0],eu1[1],eu1[2]
    c *= 1.0  # make it a real value for sure
    eu_new = Mathutils.Euler(eu_x1*c,eu_y1*c,eu_z1*c)
    return eu_new

def Eu_div(eu1,c):  # eu1 in degrees; c - constant
    eu_x1,eu_y1,eu_z1 = eu1[0],eu1[1],eu1[2]
    c *= 1.0  # make it a real value for sure
    eu_new = Mathutils.Euler(eu_x1/c,eu_y1/c,eu_z1/c)
    return eu_new


ALL tested and working mathematically correct :wink:

Regards,

Not good , Mathutils is not available in blender.exe 2.53 SVN >=31200 !
it is now mathutils!
And maybe you should not stay to component versions but Vectors!
e.g
if e1 and e2 are ‘Eulers’
mathutils.Euler(mathutils.Vector(e1) + mathutils.Vector(e1))

Perhaps TRUE… My code is for 2.49… May be somebody would wish to translate Mathutils function in 2.5x

Regards,

I just see a ‘numerical sinn’ : dividing by c without check (beter try?) if c = 0?!

and making eventual constant float use float©
Euler(float©*Vector(eulerobject)) e.g. is your constant multiplication, isn’t it

You’re right… :yes: Practically, I havent tried ALL the values in testing - just some resonable ones. In fact division function may be used very rarely and with certain reasonable values… Any way, the value = 0 should be excluded! This may get work out in several ways, such as:

Option 1:

def Eu_div(eu1,c):  # eu1 in degrees; c - constant
    if (c<0.00001):
        return Mathutils.Euler(0,0,0)
    eu_x1,eu_y1,eu_z1 = eu1[0],eu1[1],eu1[2]
    c *= 1.0  # make it a real value for sure
    eu_new = Mathutils.Euler(eu_x1/c,eu_y1/c,eu_z1/c)
    return eu_new

Option 2:
def Eu_div(eu1,c):  # eu1 in degrees; c - constant
    if (c<0.00001):
        return Mathutils.Euler(0,0,0)
    return Eu_mult(eu1,1.0/c)