Can anyone clearly explain what Quaternion.angleaxis is

I have many doubts about Quaternions maybe its because I don’t understand what that is. So can anyone explain to my what that is.

I think, at least in my opinion, this Numberphile video gives you a great introduction. I always recommend to also watch the extra bits as they mention the non commutative nature of quaternions there. Another great source are the 3b1b videos on quaternions, though they are a bit more “mathy” I guess -.-

In essence a unit quaternion is a 4d complex number system to describe rotations in 3d space. Though compared to regular complex numbers where we have one real and one imaginary component, quaternions have 4 components (one real component and 3 seperate imaginary components). A single quaternion can describe any rotation up to 180°. As you might know any rotation or orientation in 3d space can be represented by a single rotation axis and an angle around that axis. So no matter how many rotations on how many arbitrary axes you apply to an object, the overall end result can always be described by just a single axis and an angle around that axis.

In a sense that’s exactly what a unit quaternion represents. It can be mentally split into a vector part (the rotation axis) and a value that describes the angle. However the great thing about the way quaternions represent those two things (the axis and the angle) allows for easy combinations of multiple quaternions.

I’m sorry but I think we can only give you a rough overview what a quaternion is. Since this is a pure mathematical concept your understanding probably will depend on your math level. Since quaternions are an extension of the complex numbers, if you have trouble understanding complex numbers you probably won’t have any more luck understanding quaternions :slight_smile:

Though on the bottom line it’s a matter of: do you really want to understand them, or do you just want to know how they can be used. For the latter it’s only important to remember a few things:

  • In most cases you don’t want to mess around with the 4 components manually. Since rotations are described by a unit quaternion (a quaternion with a magnitude of 1), messing around with the components most likely will not do what you want.
  • In order to combine two or more rotations you have to multiply them together. Note that you should think of the first quaternion acting like a function on the second.
  • In a similar way we can rotate a vector by a quaternion by multiplying the quaternion with the vector.
  • In order to create a quaternion you usually use one of the static helper methods like Quaternion.Euler / AngleAxis / FromToRotation / LookRotation

Since you specifically asked about the “AngleAxis” method, it’s literally the closest “constructor” to what the quaternion actually describes. The best analogy is the one James Grime gave in the Numberphile video about stabbing the object with the rotation / axis vector and then rotate the object around that vector by “angle” degrees.

If you have more questions, feel free to ask, but since we don’t know your math education level it’s hard to judge what you would consider “clear”. Every attempt of explaining a complex topic has some limits. Try teaching Einsteins field equation to a 6 year old, I think we would agree that this would be pretty pointless :slight_smile:

One way to rotate is to imagine a line jammed through an object’s center like a barbecue spit, coming from any direction, which then spins. Like some sort of 3D foosball game. You have an axis, and an angle around it – angle-axis, get it? It’s one option out of many for making a rotation. This uses it to make a boring y-rotation, like a top:

transform.rotation=Quaternion.AngleAxis(r, Vector3.up);

Pretend r is gradually going from 0 to 360. Of course that’s not useful since Quaternion.Euler(0,r,0) is the same thing and easier to read. But imagine you have an arrow to a tractor beam grabbing you and want to spin around it, helplessly, as you’re dragged in:

Vector3 toEnemy=enemy.position-transform.position;
transform.rotation=Quaternion.AngleAxis(r, toEnemy);

That would be almost impossible to do using the old xyz system.

A confusing thing is that in the Inspector, all you can do is set xyz. Quaternion’s give options. You can use either xyz, or LookAt, or AngleAxis, and have the option of adding them together (that’s hard, but at least it’s possible).