Notifications
Clear all

[Closed] Quaternions to normals?

For my project I need to convert from a standard max rotation (quaternion) to a normal in the form of -1 … 0 … 1 for X and Z.

eg. I believe this would be pointing down when viewed in plan view.
normalX = -1.00 normalZ = 0.00

How would I go about doing this?

7 Replies
1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

Quaternions describe a rotation about an arbitrary axis. You can convert a Quaternion to Euler rotation which describes the final orientation as series of rotations about the 3 axes (where the order of the axes matters and there are multiple Euler solutions to the same Quaternion), or you could take axis of the quaternion.
I am really unsure what you mean when you say “convert a rotation to a normal”. If you take an existing vector, say, [0,0,1] and rotate using the quaternion, you would end up with another vector which might be what you are asking for.

Or you could convert a Quaternion to a Matrix3 and get any of the 3 axes (X, Y or Z). But there is no way to convert a Quaternion to a Normal vector without having some vector to start with.

Some more information would be necessary. You will notice that the shorter the question, the longer the answer. And you don’t want people to waste hours of their lifes guessing what you need, right

Apparently what I was looking for was:

r = copy constraint.rotation
dirX = 2 * (r.x * r.y + r.z * r.w)
dirY = 1 – 2 * (r.x * r.x + r.z * r.z)
dirZ = 2 * (r.y * r.z – r.x * r.w);

print (dirX as string)
print (dirY as string)
print (dirZ as string)

I still have no idea what the algorithm does though. Does anyone here know?

Yes, this is equivalent to converting the quaternion to a matrix3 and extracting its Y axis (row2):

(r as matrix3).row2
–> [0.233237,0.759452,-0.607317]

From my previous post:
“…Or you could convert a Quaternion to a Matrix3 and get any of the 3 axes (X, Y or Z).”

Awesome thanks. And yes, I noticed your subtle hint to buy the DVD I may just buy it.

It wasn’t intentional, it has been my signature since March 2006 when the DVD was released… But I am glad you read more into it

Ah…
I don’t know if it is exactly what has been posted here, but I’ve been fiddling and haven’t managed to do what I wanted…

The idea is that I have an alpha (a value in degrees) and I want to rotate an object by it’s pivot… how can I do that?

Thanks

P.S.: I don’t want to rotate relatively, but absolutely.

Nevermind… I managed… if anyone else would like to know how:


	 rotAtual = ($.rotation as eulerAngles).y --Will return the Y axis' rotation
	 rotTotal = rotAtual - rotValue --Object's rotation - the angle I want it to rotate to
	 rotate $ (angleaxis rotTotal [0,1,0]) --Rotate on Y axis