ValueError: math donmain error


(klopes) #1

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.


(theeth) #2

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

Martin


(jms) #3

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…

jm


(theeth) #4

use the round function might help you.

Martin


(eeshlo) #5

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 
else: 
    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:
http://www.elysiun.com/viewtopic.php?t=1184


(klopes) #6

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