View Full Version : quat, vector, angle problem
3rd Dimentia 04172012, 12:54 AM I'm not even really sure how to properly express this problem. What I want to do is derive an angle value from a quat value (compared to [0,0,1]) I was thinking of trying to find a position value to create a second vector by projecting 1 unit along the z axis of the rotated object and then use dot prouct to calculate the angle between those 2 vectors.
But...
1/ I can't remember how to project a value using a matrix. As in, if I move an object 1 unit along it's Z axis, what would the new position be. I know I've done this before, but I can't find where/how I used it.
2/ I don't know if there's a simpler way to derive an angle using a quat value and [0,0,1]
Apologies if I'm making no sense.
Cg.


3rd Dimentia
04172012, 01:49 AM
I've figure it out the long way. Maybe someone has a more elegant way
theAng = acos(dot [0,0,1] (([0,0,1] * rotSource.transform)  rotSource.transform.row4))
3rd Dimentia
04172012, 01:58 AM
This is the same thing, but a little easier to understand (for me anyway)
(
fn getWorldAngle obj =
(
vec1 = [0,0,1]  unit vector pointing up.
vec2 = ([0,0,1] * obj.transform)  calculate a position that is translated 1 unit along Z using the obj's transform as the base
vec2 = obj.transform.row4  subtract the object's position form the transform so the start of the vector is at [0,0,0]
acos(dot vec1 vec2)  dot product to find the angle between the 2 vectors.
)
getWorldAngle selection[1]
)
huijun
04172012, 05:08 AM
acos (dot [0,0,1] selection[1].transform.row3)
acos (dot [0,0,1] (normalize selection[1].transform.row3))  if object is scaled
row1, 2, 3 of transform determins object's rotation.
row3 represents local z axis of object so you don't need to get 2 points.
hope you understand my english...
3rd Dimentia
04172012, 06:34 AM
Thank you, yes I did come across that way also after I'd posted. And your English makes perfect sense. Much better than my nonexistent Korean skills. I use this matrix stuff to rarely, that I forget it by the next time I need to use it. I think I need to make myself a desktop background with all these types of maths things in it, so when I need the reference it's on my desktop somewhere.
Thanks again,
Cg.
Klunk
04172012, 08:56 AM
you can just use
acos (dot [0,0,1] node.dir)
3rd Dimentia
04172012, 08:59 AM
And the answers just keep getting better. I just tested that and it appears that by using dir, you don't even have to normalize it. Awesome. :) Cheers.
Klunk
04172012, 09:08 AM
depending on how you intend to use the result the acos really just puts the answer in a human understandable format so to speak, for most geometric operations
dot [0,0,1] node.dir
would probably surfice.
denisT
04172012, 11:46 AM
depending on how you intend to use the result the acos really just puts the answer in a human understandable format so to speak, for most geometric operations
dot [0,0,1] node.dir
would probably surfice.
node.dir.z
 angle
acos node.dir.z
Klunk
04172012, 12:06 PM
good spot denis but it's nice to use the generic version so your remember what you were trying to do.
denisT
04172012, 12:11 PM
good spot denis but it's nice to use the generic version so your remember what you were trying to do.
probably i'm from old school but for me was easier to remember that projection is the cosine...
CGTalk Moderation
04172012, 12:11 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002015, Jelsoft Enterprises Ltd.