squaring a negative exponent number, not working!!:(

23 views
Skip to first unread message

e955...@gmail.com

unread,
Oct 9, 2014, 5:40:06 AM10/9/14
to python_in...@googlegroups.com
hello all,

i couldnt figure this one out for ages. I am doing pythag on a normal vector with values:

x: 0.952419936657
y: 0.304788768291
z: 9.01522412278e-07

i didnt realise but it seems maya couldnt process the 'e-07' part of the z direction. so if you square it z*z you get 81.274265984 rather than the tiny number it should be

does anyone know how make python deal with a number like 9.01522412278e-07 ? so its in decimal form?

any help would be awesome,

thanks,
Sam

Paul Molodowitch

unread,
Oct 9, 2014, 9:55:42 AM10/9/14
to python_inside_maya
It's extremely unlikely that maya or python "couldn't process" a floating point and do basic multiplication.  I, for instance, get:

>>> z = 9.01522412278e-07
>>> z * z
8.127426598395442e-13
>>> z ** 2
8.127426598395442e-13

...which seems right. Take another look at what you're doing, and you'll likely find the mistake is on your end (or possibly a third party library's), not maya or python.  If you're still not sure what you're doing wrong, post exactly what you're doing (ie, code), and maybe we can help.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d96dc0d3-4673-45d4-977f-c1ebbc4beb41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

e955...@gmail.com

unread,
Oct 9, 2014, 10:18:14 AM10/9/14
to python_in...@googlegroups.com
ummm, well let me show you what im trying to do. i need to normalise a vector

so ive got

x= 0.952419936657
y= 0.304788768291
z= 9.01522412278e-07

so i do pythag

pythag=math.sqrt((x*x)+(y*y)+(z*z))
pythag=0.999999964509

x=0.952419936657/pythag
y=0.304788768291/pythag
z=9.01522412278e-07/pythag

so after this, all values need to be less than 1 right?

but z is like this: 9.01522444274e-07 .which i cant use as unit vector. i think it needs converting to decimal or something?

Paul Molodowitch

unread,
Oct 9, 2014, 11:48:02 AM10/9/14
to python_inside_maya
Normalizing means making the length of a vector == 1.  In your code, the length is given by "pythag".  And it's already one (nearly). So normalizing it does nothing.

You say "all values need to be less than 1"... which is correct.  But your z value is fine.  9.01522444274e-07 < 1.  (It's really close to zero, in fact.)  Why do you say you can't use it "as unit vector"? It is PART of a unit vector...

I think you probably need to review your basic vector math...



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

e955...@gmail.com

unread,
Oct 9, 2014, 12:44:28 PM10/9/14
to python_in...@googlegroups.com
cool thanks,

its working now. i just realised it was because i was checking if the value was usable by pasting the z result into the direction z field in maya, and it couldnt read the value with e-07 at the end. i fed it in as a variable name in my script and it works now.

thanks for your help,
Sam;)

Reply all
Reply to author
Forward
0 new messages