renderfan Posted January 31, 2012 Share Posted January 31, 2012 I would like to measure angle between two vectors in python. I know about hou.Vector3.angleTo() and hou.Vector3.dot(). For both examples (see picture) i get 90 degree. I there way how i can get 90 and 270 degree. Thank you!! Quote Link to comment Share on other sites More sharing options...
magneto Posted January 31, 2012 Share Posted January 31, 2012 I haven't used hou.Vector3.angleTo but is it giving you 90 for both red vectors in the directions as you depicted? If so, maybe try to calculate the angle yourself: theta = acos (dot (v0, v1)) 1 Quote Link to comment Share on other sites More sharing options...
renderfan Posted January 31, 2012 Author Share Posted January 31, 2012 I haven't used hou.Vector3.angleTo but is it giving you 90 for both red vectors in the directions as you depicted? If so, maybe try to calculate the angle yourself: theta = acos (dot (v0, v1)) Thank you for answer but i tried this allready. I get same result. I think it has to do with direction of rotation, but i do not know how to check. Thank you again! Quote Link to comment Share on other sites More sharing options...
Macha Posted February 1, 2012 Share Posted February 1, 2012 Can't you just use one and then subtract it from 360, so that you get both? Quote Link to comment Share on other sites More sharing options...
gaurav Posted February 1, 2012 Share Posted February 1, 2012 Can't you just use one and then subtract it from 360, so that you get both? They call it out of the dot product thinking !! Nice.. Quote Link to comment Share on other sites More sharing options...
edward Posted February 2, 2012 Share Posted February 2, 2012 The problem of course is that sometimes you want to know which one though. In that case, it's not possible without having a third vector as a "hint" to give the desired angle. Quote Link to comment Share on other sites More sharing options...
eetu Posted February 2, 2012 Share Posted February 2, 2012 Yeah, I think to get a good solution, you would need to know the other vectors/lines as well, the ones in black in your picture. Or at least the position as well as direction of the red vectors. Quote Link to comment Share on other sites More sharing options...
Macha Posted February 2, 2012 Share Posted February 2, 2012 I have an idea for this but its a bit stupid because there is an arbitrary element to this. Anyway...somehow decide how you will choose the smaller and the bigger angles depending on those red lines. According to that decision decide whether you do A cross B or B cross A. You will then get a third vector C. Put all of these into a matrix and calculate the determinant. Now with the sign you know whether it is right handed or left handed, and so whether you are dealing with the big angle or the small one. Something like that. Quote Link to comment Share on other sites More sharing options...
renderfan Posted February 3, 2012 Author Share Posted February 3, 2012 Thank you all for replies!! I did search in the internet and i found only ways to positive and negative angle when i have a third vector, as Edward and eetu said. I have an idea for this but its a bit stupid because there is an arbitrary element to this. Anyway...somehow decide how you will choose the smaller and the bigger angles depending on those red lines. According to that decision decide whether you do A cross B or B cross A. You will then get a third vector C. Put all of these into a matrix and calculate the determinant. Now with the sign you know whether it is right handed or left handed, and so whether you are dealing with the big angle or the small one. Macha, i am sorry but i do not understand how i can do this. I found determinant in vops but do not know how to use it. Can you kindly show me example how you would do it? Thank you!!! Quote Link to comment Share on other sites More sharing options...
Macha Posted February 4, 2012 Share Posted February 4, 2012 (edited) Hey Erik, unfortunately I haven't been able to post hips for quite a while (hopefully that will change soon) so I will describe it as best I can. In a vopsop get your 2 vectors. A good way of doing that is via import attribute and setting a constant point as input, so that you don't iterate over all points. The vectors will have to be on 0, so transform that if necessary. Append a vec to float. Then add a matrix3 and set either rows or columns of it as the components of the 3 vectors. So, all of vec1 in row1, vec2 in row2, vec3 in row3. Then append a determinant node and a sign node. I believe rows/colums doesn't matter and that (hope) the incoming vecs don't have to be orthonormal. But yeah, I dont know if it is all that useful because by the time you figured out if you cross A by B or B by A you may already have all you need to decide if you deal with the bigger or smaller angle. I'm just think aloud as it were. Edited February 4, 2012 by Macha Quote Link to comment Share on other sites More sharing options...
magneto Posted February 7, 2012 Share Posted February 7, 2012 Hey Erik, unfortunately I haven't been able to post hips for quite a while (hopefully that will change soon) so I will describe it as best I can. That's an interesting way to say you are part of H12 beta Or maybe I am reading too much into it. Quote Link to comment Share on other sites More sharing options...
renderfan Posted February 8, 2012 Author Share Posted February 8, 2012 Thank you Macha!!! I did follow your instructions and it worked perfect. Exactly what i needed. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.