Grasshopper

algorithmic modeling for Rhino

Hey all, so i'm totally new to scripting and i'm wondering how can this be done

Evaluate the angle (a) between a vector and x axis

If (a) is positive

then rotate the vector about z axis with angle value (-a)

else rotate the vector about z axis with angle value (a)

I thought of dispatching the vector list with a logic button on gh and having two rotation "processes", but the problem is that i need the original order of the list for later operations

Thank in advance!

Views: 4370

Replies to This Discussion

i am not sure which language are you trying to learn .. but i wrote a little example of how it could be done in python .. 

you can also read the Rhinopython Primer from here

i hope that helps

Attachments:

In scripting the following steps would be done like this:

(a) double angle = Vector3d.VectorAngle(v1,v2);

(b) b.Transform(Transform.Rotation(angle, Vector3d.ZAxis, Point3d(PointToRotateAround));

I'm not sure why you would need the positive or negative check. Because it would result in the following redundant code:

if (angle < 0)

{

  // angle is negative, use a negative angle to rotate

  b.Transform(Transform.Rotation(angle, Vector3d.ZAxis, Point3d(PointToRotateAround));

} else {

  // angle is positive, use a positive angle to rotate.

  b.Transform(Transform.Rotation(angle, Vector3d.ZAxis, Point3d(PointToRotateAround));

}

I am curious how this could be solved too.
VectorAngle method, always calculates an angle between 0 and pi range. So I guess you could only predict that if your vector is in either first or second quadrant, then the angle is positive. Or if it is in third or fourth, then it's negative. Meaning just check for the vector's Y value. If it's > 0 the angle is positive, otherwise it's negative.

You would need another vectorAngle function using atan2:

http://stackoverflow.com/questions/10133957/signed-angle-between-tw...

Have got a pice of code lying around on another computer, can look for it on tuesday.

Richard

Thanks Richard.

This was indeed the method i ended up using!

I think what you should be using is Vector3d.VectorAngle(v1,v2,plane) RhinoCommon

by incorporating the Plane you will always get the angle measured in the same direction 0 to 360 degrees.

The GH method:

Thanks Danny.

Hmm somehow missed this, didn't know the vectorAngle component could do that.

So to make it work in 3d I would need to construct the plane defined by the two vectors first (cross product->plane from normal) and than apply the component?

Plane from normal wouldnt work as the possibilities are ifinate gh will change the plane depending on what they are. I have a sneaky suspicion this is what it does when you supply only 2 vectors. Ypu will need to come up with a more defined plane like using one of the vectors to define an axis

This is interesting Danny.
I have just tried using cross product of two vectors to feed the "Plane Normal" component - and then feeding that resulting plane to the "Angle" component, and it worked.

Can you get an angle larger than 180 degrees

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service