Grasshopper

generative modeling for Rhino

Why the "angle between vectors" component is always positive?

I have to know the angle between a lot of vectors, but some times this should be negative, I thought that this component measure the angle in the direction of the clock.

Any idea of how can I get the real angles, negative and positive???

Tags: grasshopper

Views: 2266

Reply to This

Replies to This Discussion

This answer will always be positive because A)in order for there to be a negitive angle there needs to be an defined axis and B) having a negitive rotation implies going from condition A to condition B and the angle component is only concerned about the absolute angle between the two vectors.

Its very hard to say how exactly to get you the rotation that your looking for without really knowing what your working with. Ultimately though, the angle is there, so you just need to find out what condition needs the postive version of it, and what condition needs the negative version. This will largely depend on how you setup your axis, because you can rotate different ways depending the orientation of that axis.
This has always bothered me as well.... I took some time today and wrote a def. I hope this helps.

Input a 'base' point and an 'evaluation' point, and the def returns the absolute angle, measured counterclockwise from the positive x-axis (like we all remember from geometry class!).

definition:
Attachments:
Here's the way that I handle this (pretty much Damien's method.)

1) Calculate the difference in the normal way.
2) Measure each one against a reference in my case Y vector
3) Compare each referenced angle to find which is greater
4) Pass the True/False trough a replace string to get -1/1 instead of 0/1
5) Multiply the actual angle by these to get negative and positive angles


It looks a bit clunky because of some limitations I came across with the way GH handles strings. In an ideal world I would like to have just replaced ZERO with -1 but because of the special character "-" I had to change 1s for 2s and then subtract 1 again.
Danny,

This might be a touch cleaner. You can still work with booleans for the subtraction.

Implementing and testing Taz's boolean switch made me realize that the method I outlined above does not work for every condition. My definition had fairly small angles to measure predominantly in the NE to SE sector of the compass if there was a W factor in it I don't think this would work.
:(
I think there's a more reliable way to do all this, but in pure GH components its way messier than it needs to be. I'll write a script or a component tomorrow to do this and it will make it easier. Essentially, it will take the axis for the rotation from the plane that's created by the normals, and make that axis always point in a reliable direction (which ATM would be up, i guess), then I'll make it output the positive and negative angles...maybe with the option to switch between radians and degrees...
Sorry Taz, I forgot to say nice booleans
Alright, so let me explain the situation even more and maybe someone can step in a say what they'd like to see. So as I originally wrote, there has to be a defined axis in order to have negitive rotation, so the first order of business is finding a relaible axis to base the rotation on. Two vectors will create a plane, so I figured I'd use that. Essentially, what winds up being the Z vector of the plane is the cross product of the two vectors (provided those vectors are unitized, which they should be). The thing about the plane that's created is that A) it will always be right handed, B) the X vector will always be the actual X vector of the plane, and C) the supplied Y vector will give direction to thw Y vector of the plane, although it won't actually match it.

Well, when you take the angle between the two vectors, it will always give you the angle (in radians) between the two vectors that is less than 180 degrees. If you use the Z vector of the plane created from those two vectors as the axis of rotation, then the rotation from vector A (the x vector of the plane) to vector B will ALWAYS be less then 180 degrees and the result from the Vector Angle component will always lead to the "correct" location.

My assumption as to why some of you would want a "negative" rotation was simply because you were rotating with a static axis which was some times leading to the "wrong" result (ie one that doesn't result in going from vector A to vector B). However, if you create the axis based on each condition that your working with, then you can completely avoid that problem.

So I guess my question is more of where does the situation come up where you NEED the reflex angle between the two vectors. IMHO, that need comes out of using the same axis/plane for each rotation situation as opposed to using the natural axis/plane that is generated from each one. Even if you have a set axis that your trying to use, you could potentially compare it to the natural one to see if you need to generate a negative rotation. Maybe its just me, but if someone can shed more light, then maybe I could help out a bit more.

BTW, I have a definition exploring everything above if someone would like to see it...
Damien wrote: "So I guess my question is more of where does the situation come up where you NEED the reflex angle between the two vectors."

Below is the interpolated vector grid for a river's current velocities, I had to sample some survey data and then interpolate between them along the river to get this grid for use in a maneuvering simulator.

The method I used needed to rotate the vectors and change their magnitude in the space between measuring stations. As these were only small angles the outlined method above worked but it was necessary to determine direction of rotation in order to achieve the results.

The example is only needed in 2D referencing the North direction of a compass and as none of the vectors made it passed south there was no sign of anything amiss with the method used. But I would appreciate a universal method to account for all positions of the compass.

Attachments:
Damien,

Off the top of my head one example I can think of would be if you were trying to fabricate an undulating surface. There would be the process of panelizing (let's say triangulating) the surface with flat panels and then trying to devise connectors between each panel.

Assuming the surface has a front face and a back face condition (aesthetics or something) the connectors would (in some cases) need to register an obtuse (or reflex?) angle for consistency of construction.

I can dig up an example if that's not clear enough, but I think that would be a pretty generalizable need...

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

© 2013   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service