Getting the angle between two 3d vectors in VOP

   33313   13   2
User Avatar
Member
27 posts
Joined: Jan. 2007
Offline
Sorry for the basic math question, but I'm trying to replicate the functionality of Softimage's “Get Angle Between”, which takes two normals and outputs the inbetween angle, and I'm blanking. I'm using VOP.

I'm guessing it's not as simple as just subtracting the two?
Edited by - Dec. 21, 2009 15:18:43
User Avatar
Member
696 posts
Joined: March 2006
Offline
vangle() expression do what you're looking for?

float vangle (vector v0, vector v1)
Returns the angle between two vectors
Stephen Tucker
VFXTD
User Avatar
Member
27 posts
Joined: Jan. 2007
Offline
What is that in VOP speak? Can I use expressions with vop?
User Avatar
Member
1390 posts
Joined: July 2005
Offline
negow
Sorry for the basic math question, but I'm trying to replicate the functionality of Softimage's “Get Angle Between”, which takes two normals and outputs the inbetween angle, and I'm blanking. I'm using VOP.
I'm guessing it's not as simple as just subtracting the two?

In VOPS land plug Dot Product VOP into Trigonometric Functions VOP selecting Arc Cosine as a function of it. This gives you an angle in radians, which you can convert to degrees with Radians to Degrees VOP. Note, vectors should be normalized!

hth,

ps. angle = acos(dot(normalize(v1),normalize(v2)))
User Avatar
Member
27 posts
Joined: Jan. 2007
Offline
Awesome, Thanks!

Would you mind explaining, for someone who missed that class, how the Arc Cosine works to output the inbetween angle in this scenario?
User Avatar
Member
1390 posts
Joined: July 2005
Offline
negow
Awesome, Thanks!

Would you mind explaining, for someone who missed that class, how the Arc Cosine works to output the inbetween angle in this scenario?

Well, I'm not the best person to explain math, but basically the magic thing is a dot product or scalar product, that relates to a projection of vector A on vector B. A' = |A|*cos(angle). Because arc cosine is an inverse function to cosine, you can use it to retrieve angle from above relation (and by using normalised vectors you cancel multiplication). Check out wiki: http://en.wikipedia.org/wiki/Dot_product [en.wikipedia.org]

cheers!
skk.
User Avatar
Member
320 posts
Joined: Aug. 2007
Offline
Don't you need to divide the dot by the magnitude before arcos? My notes have this.

cos i = v.w / |v||w|

This returns the cosine of the angle between the two vectors, so you'll need to use arcos (invert cos) to get the angle.
www.alan-warren.com
User Avatar
Member
1390 posts
Joined: July 2005
Offline
Alanw
Don't you need to divide the dot by the magnitude before arcos? My notes have this.

cos i = v.w / |v||w|

This returns the cosine of the angle between the two vectors, so you'll need to use arcos (invert cos) to get the angle.

unless you normalize v and w I guess… :roll:
User Avatar
Member
152 posts
Joined: June 2008
Offline
two great resources for this:

Houdini specific:
http://www.3dbuzz.com/xcart/product.php?productid=58 [3dbuzz.com]
Peter Claes uses quite a bit of vector math and does a great breakdown of using the dot product and cross product for a few scenarios!

3DS MAX Specific - Which I don't use, but wanted to find some more material on 3D Math… The CG Academy's - MAXSCRIPT 3 DVD - The Matrix Explained…

Fantastic resource for getting a good understanding of 3D Math from vectors to matrices and their uses in 3d

Cheers,
Jonathan
User Avatar
Member
320 posts
Joined: Aug. 2007
Offline
SYmek
Alanw
Don't you need to divide the dot by the magnitude before arcos? My notes have this.

cos i = v.w / |v||w|

This returns the cosine of the angle between the two vectors, so you'll need to use arcos (invert cos) to get the angle.

unless you normalize v and w I guess… :roll:

doh!

www.alan-warren.com
User Avatar
Member
27 posts
Joined: Jan. 2007
Offline
Great advice guys, and thanks for the explanation SyMek!
Guess I'll go through those dvd's, once and for all )
User Avatar
Member
617 posts
Joined: Aug. 2008
Offline
thanks symek, just used you trick
symek
angle = acos(dot(normalize(v1),normalize(v2)))

I will just add
VEX
float angle = degrees(acos(dot(normal_pt, nn_pt)));

in case you need it on degrees
User Avatar
Member
4 posts
Joined: Oct. 2010
Offline
pelos
http://en.wikipedia.org/wiki/Dot_product [en.wikipedia.org]
what is normal_pt and nn_pt ?
User Avatar
Member
2041 posts
Joined: Sept. 2015
Offline
what is normal_pt and nn_pt ?

They are two user-defined vectors for the dot function.

http://www.sidefx.com/docs/houdini/vex/functions/dot.html [www.sidefx.com]
  • Quick Links