Notifications
Clear all

[Closed] quat, vector, angle problem

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.

10 Replies

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))

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]
 )

  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…

Thank you, yes I did come across that way also after I’d posted. And your English makes perfect sense. Much better than my non-existent 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.

you can just use

acos (dot [0,0,1] node.dir)

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.

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.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

 node.dir.z
-- angle
acos node.dir.z
 

good spot denis but it’s nice to use the generic version so your remember what you were trying to do.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

probably i’m from old school but for me was easier to remember that projection is the cosine…