Jump to content

[SOLVED] Compute angle between unshared edges


Alain2131

Recommended Posts

Hi there !

The title might not be clear much, so let me try to explain. I'm trying to compute the angle of each points inside of a hole in a geometry.
By searching a bit, I found float angle = degrees(acos(dot(normal_pt, nn_pt)));, which works, but there is an issue with my specific case.

image.png.afe673626f7bcdc327676246545f269b.png

The blue angles are fine (simply by luck, coming from the shape of the hole), but the red ones are incorrect.
Instead, I want to get the orange angle. That's pretty easy, I can do 360-angle. But the issue is when. How do I detect those issues, to be able to apply the fix ?

Alternatively, I tried using the Measure SOP to compute this all for me, but I didn't find how to use it in this manner. But knowing Houdini, there probably is some node or VEX function that can compute this for me already =P

Thanks !

getHoleAngles.hipnc

Edited by Alain2131
Link to comment
Share on other sites

Hi,

acos(dot(v1,v2)) is always getting the smallest angle between two vectors. If you want to get orange angles, you have to add an orientation information like a point normal. With the normal and the first edge you can construct a plane, to

determine, if the second vector is on the positive or negative side.

getHoleAngles_mod.hipnc

 

@edit: I am not sure, if this solution works in every case, because it probably depends if the hole is on the left or right side <- but this should work because the angle will change aswell ....

Edited by Aizatulin
  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Another way to do this is to construct a matrix from the point normal and your two vectors, then find the determinant of the matrix and use it and the dot product to find the angle.

vector N = point(0, "N", P0);

float dot = dot(v0, v1);

matrix3 mat = set(v0.x, v1.x, N.x,
                  v0.y, v1.y, N.y,
                  v0.z, v1.z, N.z);
float det = determinant(mat);
return (360 + degrees(atan2(det, dot))) % 360;

getHoleAngles.hipnc

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Hi @Aizatulin,
that works like a charm !
To be honest, I tried to figure out the logic of it, but I guess my intuition and understanding will develop as I use it in various situation. Right now, I'm having trouble wrapping my head around it, even if it's just a simple dot product -_-'

@eimk, thanks for the alternative method ! I'll have to take a look at it later, and figure out that determinant thing

Thanks to you both again, I appreciate it !

Link to comment
Share on other sites

  • Alain2131 changed the title to [SOLVED] Compute angle between unshared edges

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