Quaternions
Hello, can anyone tell me the exact meaning of the [x,y,z,w] components of a quaternion returned by a .getQuat() function? I am particularly interested in the range these values can take, especially w.
This might seem like a silly question, but are the two quats returned in this script in the exact same format (i.e., same ordering of components, scaled in the same way, etc.)? Code:
... |
The meaning of the x,y,z,w components of a quaternion are similar to the meaning of axis-angle components. the [x,y,z] values represent the axis of rotation. The amount of rotation about that axis in radians is, 2 * acos(w). Keep in mind that Vizard uses a left-handed coordinate system.
All the plugins should return quaternions in the same order (x,y,z,w). I'm assuming most devices will return normalized quaternions as well, but I'm not 100% sure about that. |
Thanks farshizzo, I appreciate it.
Now knowing that my math is all wrong you can disregard the script I've sent you (as mentioned here). |
All right, I've read QUITE A BIT about quaternions at this point but still don't get them .. :(
Here's some sample code. Copy/paste and run this: Code:
import viz What this is meant to be is "training grounds" for understanding quaternions. If you look at the code inside the while loop you'll see that X-axis is traced with red dots, Y with green, Z with blue (X-Y-Z -> R-G-B was my logic :o). MainView's originally just slightly off red Y-axis and the rotation is set to [x,y,z,w] = [0,1,0,0]. What I'm trying to understand now that we have a well-defined system of coordinates right in front of us :) is how quaternions work: [0,1,0,0] SHOULD have defined a rotation of 0 degrees around axis [0,1,0] - the Y-axis, so the camera originally should just look down the green Y-axis. Instead we're looking down X! I hope someone more experienced with quaternions can explain to me how they work in Vizard using this simple script, that would be great. Thanks! |
In my previous post I explained what the values mean. So given the quaternion rotation of [0,1,0,0], this would mean a 180 degree rotation around the Y axis (2 * acos(0) = 180 degrees). Printing the euler and axis-angle values of the main view after applying the quaternion will confirm this. Adding the following code at the end of the script:
Code:
print viz.MainView.getEuler() Code:
[-180.0, 0.0, 0.0] |
Damn, forgot about that acos. Then to get no rotation I need to use w=-1: 2*acos(-1) = 360 degrees. Thanks again farshizzo!
EDIT: The following code makes MainView look down X. Code:
import viz |
Now you're dealing with non-normalized quaternions, so all bets are off. In general, you don't need to deal with quaternions at such a low level. You can use Vizards matrix routines to deal with rotation transformations.
|
Quote:
For example, add this function definition to my previous code: Code:
# Normalizes the passed quaternion (which is assumed to have the form Quote:
|
Yes, Vizard will internally normalize all quaternions that are passed to the setQuat function of nodes, views, and bones.
|
All times are GMT -7. The time now is 02:26 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC