7
$\begingroup$

I want to create a lamp in blender using python. I want to give the lamp some rotation. As per the documentation I can set the initial rotation using a tuple of numbers in the function call like this rotation=(0.0, 0.0, 0.0) this is the specifc documentation for the rotation parameter:

rotation: (float array of 3 items in [-inf, inf], (optional)) – Rotation, Rotation for the newly added object

What units is this parameter specified with? It does not seem to be in degrees or radian.

When I try with my example code here where I use rotation=(0, 1, 0) to get 1 degree on the y axis. I end up getting 57.296 degrees after running the code.

import bpy

bpy.ops.object.lamp_add(type='AREA', view_align=False, location=(0, 0, 0), rotation=(0, 1, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

enter image description here

$\endgroup$
1

2 Answers 2

17
$\begingroup$

It is using radians. 1 radian = 57.2957795 degrees. Without the need to import another module you can use a degree value with (3.14159 * degrees / 180) or just quickly import pi from math if you don't want to define it or you could alternatively use round(math.radians(degrees)).

import bpy
from math import pi

bpy.ops.object.lamp_add(type='AREA', ... ,  rotation=(0, (pi * degrees / 180), 0))
$\endgroup$
4
  • $\begingroup$ indeed it is radians $\endgroup$
    – Vader
    Commented Feb 17, 2014 at 0:02
  • 5
    $\begingroup$ I recommend to from math import radians, degrees for two handy functions to convert back and forth. $\endgroup$
    – CodeManX
    Commented Feb 17, 2014 at 0:15
  • $\begingroup$ Are the rotation angles meant to be Euler angles ? (I haven't had much luck finding this stated in the documentation and a search on this site led me to this question, so it seems the most appropriate place to ask, rather then generating a new question.) $\endgroup$
    – Carel
    Commented Dec 27, 2015 at 9:55
  • $\begingroup$ @Carel Yep. Blender's rotation system implements a famous paper IIRC. $\endgroup$
    – iKlsR
    Commented Dec 29, 2015 at 0:55
5
$\begingroup$

There is build-in functions for this purpose

import math
print math.radians(90)
print math.degrees(1.57)

They can be referred from the python mannual https://docs.python.org/2/library/math.html

line 2 translate 90 degree to corresponding radian. line 3 do the opposite thing to translate 1.57 rad to 90 degree.

$\endgroup$
1
  • $\begingroup$ Could you elaborate a bit on what those functions do and why they work, please? $\endgroup$ Commented Aug 7, 2017 at 0:28

You must log in to answer this question.

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