ValueError: math donmain error

What that means? It happens in my script, sometimes, and sometimes not, at the acos, asin,… functions.

And arguments are between -1 and 1, of course.

are you 100% sure they are between -1 and 1? Otherwise, I don’t really see why it should give you that error.


Sometime in blender floats are not exactly -1.0 or 1.0
but -1.00000145524466 or 1.00000145524466.
Put “print argument” in the line before
and see the results when errors happen…


use the round function might help you.


I wouldn’t really advice rounding, just clamp the value, something like this:

if t<-1.0: 
    angle_y = 1.570796327 
elif t>1.0: 
    angle_y = -1.570796327 
    angle_y = -asin(t) 

or slightly different like this:

angle_y = -asin(max(min(t, 1.0), -1.0))

The matrix topic continued in the realtime forum, you can find some shorter functions there, in case you find it useful:

Thank you for all, the problem is deeper in the code than I though…