Vector.angle_between() -- Direction?
-
I'm trying to rotate a comp inst so that it is parallel to the green axis. I have a vector that represents the component, and I use that vector's angle_between method to create a (rotation) transformation object to apply to my comp inst. It works right most of the time, but sometimes, it rotates in the wrong direction. It seems that angle_between never returns a negative value, even if I want to rotate in a "backwards" direction. Is there a better way to find the angle? Thanks, CB.
-
The angle_between method returns a value between 0 and PI, so 270° is the same for it than PI/2
This is really a weird way of returning angle IMHO 8O
Nobody knows (at least not me) why 'they' coded this that way.
I'm afraid you'll have to test the two vectors to know in which trigonometric quadrant (0°->90°,90°->180°,180°->270°,270°->360°) they are, to get the "real" angle between them.
But perhaps you could also use this:
your_component_instance.transformation.yaxis = your_angle
Hope this helps -
Thanks, DB, that helps a lot.
I just changed my code to try using the angle_between angle, and then check the result to see if it's where I expect it to be. If not, then I reverse the angle, and try again. Lots of code, but correct behavior now! Thanks again. CB.
-
I created a vector1.flat_angle(vector2) method that does this work for you.
-
Where's this gem, Rick ? I don't see it at smustard
-
If you have pathcopy.rb you get vector.flat_angle.rb...
-
OK OK OK
Thanks for answering., have a nice day -
Yeah, sorry about that. I suppose I shoul give it its own spot for developer use
Advertisement