I ve been fiddling around with creating meshs using NMesh, and have stumbled across Eulers and Quternions in the Blender Python API. Can anyone point me in the direction of more information about them? THey look pretty useful, I just can’t work out what they are! lol

# What are Eulers and Quaternions?

**MrMuscly**(MrMuscly) #2

Those are both quite advanced mathematical functions I believe. You could try googling for them. Or checking them up at wikipedia or such. I can’t tell you exactly what they’re about since I don’t even know so myself ^^.

But well, should be about 3D stuff

Good luck and I hope I helped out a bit.

**Brandano**(Brandano) #3

Euler angles are rotation angles relative to the world x, y and z axis. The name comes from a greek mathematician that first devised them, some centuries before a nice guy said a lot of nice things and got nailed up on a cross for that. The problem with eulers is that you must be careful in the order you apply them, because you can end up in a situation called of “gymbal lock”, where you bring one of the axis to match with another and the result of the rotation isn’t what you meant to obtain.

Blender python eulers are represented by their own class, but you can treat them as a list of 3 values in degrees. Yep, degrees, so much for consistency.

Quaternions are much more recent, being only a couple of centuries (I believe) old. They are a way of defining a transformation defining an axis around wich to revolve, and specifying an amount of rotation. They’re more comlpex to understand, and less intuitive to work with, but they’re easier to use where you have to interpolate between values, and are immune to gymbal lock by definition. Blender quaternions are a little odd, as the constructor behaves differently depending on the values passed to it. I believe (but this is only my interpretation) that

```
quat = Mathutils.Quaternion([w,x,y,z])
```

will create a quaternion for a rotation of w around an axis defined by the (x,y,z) vector,

while

```
quat = Mathutils.Quaternion([x,y,z],w)
```

will do exactly the same, but with a different syntax. Naturally, i don’t really know much about quaternions, and I personally try to keep away from Eulers. I managed to understand the way matrices work, and that’s enough for me at the moment

**stiv**(stiv) #6

Leonhard Euler was a Swiss mathematician who lived in the 1700s.

Wikipedia is a web-based encyclopedia.

Don’t you people have Google on your planet?

**ascotan**(ascotan) #9

Eulers, quaternions and matrices are ways of dealing with rotations in 3D space.

When you want to describe something in 3 dimensions you can give it a location (point, vector) and a rotation (euler, quaternion, matrix).

Why so many? Because each has it’s own special usage.

1)Eulers are very simple conceptually - each value represents a rotation along the x,y,z axes respectively. [20,20,40] is a +20 rotation on the X, +20 rotation on the Y and a +40 rotation on the Z. People likey Eulers because the take very little computer space and are conceptually simple. They do however suffer from 2 things.

a) not all values are a unique rotation. It’s valid to have a rotation of 10000 degress (which is of course many circular rotations around an axis). This produced weird animations.

b) gimble lock - which is a mathematical problem where sometimes one axis gets 'stuck’and the rotation doesn’t do what you expected.

2)Quaternions are complex conceptually. They really represent a vector + and angle although technically a quaternion is a complex number (a +ib) and has some bizare math because of this. The beauty of of the quaternion is that it avoids all of the above problems of eulers plus you can do something neat with them - interpolation . If i have quaternion1 which represents a rotation at t=0, and then i have rotation 2 at t = 10, I can calculate any roation inbetween (this is called interpolation) using the Slerp function.

Slerp(quat1, quat2, 50%) will give me a new rotation at t=5. This way you can calculate smooth interpolated animation.

So quats avoid all the issues of eulers, do interpolation and only take 1 more spot of memory to boot.

- matrices represent a rotation + a location. They are nice because matrices are like a big package. They include all the information about the rotation and position of an object. They also include information about the scale of the object, it’s shear, ect. The problem with matrices is that they are memory hogs and matrix math is fairly memory intensive. However it’s very easy to apply a rotation to another object by:

rotMatrix * object.matrix = object rotated by rotMatrix

So they all have uses and advantages and disadvantages which is why they all co-exist

**sundialsvc4**(sundialsvc4) #11

I believe that “gimbal lock” occurs when one of the rotations is, say, 90 degrees. Rotate “X” by 90 degrees and you get “Y.” Specify a 90-degree rotation of “X” *and* some rotation of “Y”, using Eulers, and you get weirdness.

I know that some advanced processors have a built-in array processor, *specifically* to do matrix arithmetic. These big-boys have physical arrays of floating-point engines that can operate on a complete matrix simultaneously. I believe that the PowerPC P6 has this, for example. I don’t know what others do. Graphics-cards (GPUs) of course have this big-time, but I don’t know that Blender is able to exploit them.

**cyborgxs**(cyborgxs) #12

cheers brandano and ascotan, that helps a lot. Wikiopedia pages also very good cheers MrMuscly. I was looking at mathworld.com, also v cool but a little beoyond my ken, %| . thanks again for all your advice.

**cyborgxs**(cyborgxs) #13

One last question: what does it mean to normalise vector? ie what happens when I run the normalize method on a vector object?

**ascotan**(ascotan) #14

A normalized vector is also called a ‘unit’ vector.

Vectors can have any length, however a vector with a length of 1.0 is a special vector called a ‘normal’ or a ‘unit vector’.

When you normalize a vector you reduce it’s total length to 1.0.

**cyborgxs**(cyborgxs) #15

If anyone is lookinmg for more information about matrices, eulers and quaternoins, I ve just found http://www.euclideanspace.com/ which is excellent. Now I understand,