Jump to content

normal to angle : how to ?


vbk!!!

Recommended Posts

You want the dot product between the two vectors which is a float that returns a half cosine (which is how Lambertian shading is calculated from the eye and the surface normal). Convert result with an arccosine to get your angle in radians, then a degrees() to convert from radians to degrees (vex/vops are always in radians).

angle_deg = degrees(acos(dot(normalize(vector A), normalize(vector B ))

Or just copy-paste the VOP SOP from the attached hip file. :)

Pick up the hip file from the post below. It has both angle float and angle vector examples in there.

Edited by old school
Link to comment
Share on other sites

If you want the Euler rotation between two vectors, you can use matrix3 dihedral( vector_A, vector_B ). This returns a matrix3 that can be converted to Euler rx, ry and rz.

See the attached hip file for a vop implementation and is set up just to copy-paste and change the parameters to match attributes name same as above file.

Note that this will flip around 0 and 180.

angle_between_two_vectors.hip

Edited by old school
  • Like 1
Link to comment
Share on other sites

  • 5 months later...

Hello,

thanks for this very useful post. I tried doing the same but Im not quite getting there. If I try to attach it to a point, it kind of works but it flips at 360 degrees, upside down momentarily. But if I try to attach say a null to the normal of a rotating cube it goes very wrong. Would appreciate any help.

Cheers.

angle_between_two_vectors_Problem.hip

Link to comment
Share on other sites

  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...