Euler Angles from vector


I am using an component of a plugin that rotates special geometry with Euler Angles. It functions the same way as Rotate Euler from Pufferfish.

I want to align a cylinder with a segment of a line using Euler Angles – Is there a way to calculate the angles from a vector? I cant figure it out.

I know that one angle is undefined since a vector allows for indefinite configurations along it’s axis. But in the example case, since the cylinder is rotational symmetric, rotation along the the vector should not play a role.

many thanks! (8.7 KB)

Given a valid Vector3d V, Euler angles are:

This assumes that the Plane.WorldXY is used otherwise a “V map” to any different Plane axis is required.For instance given any valid Plane P:

vx = V.Length * Math.Cos(Vector3d.VectorAngle(V, P.XAxis);

etc etc


unfortunately the script does not produce the angles required to align the cylinder to the line;
Could you have a look? (15.4 KB)

angles are always tricky, here it is just the order of operation.
First I calculate Azimuth, angle from above and as cylinder is oriented on Y I use Y and I project vector on plane XY.
Then I calculate the elevation around X’ (plane XY rotated by Azimuth)
So In plugin ask first for Z (2) then X(0) !! (16.3 KB)


As Laurent said … angles are a tough cookie. I’ll prepare some far more explicit C#.

In the mean time IF your goal is “just” cylinders VS lines … see this indicative/simple take (using classic PlaneToPlane trans). The C# counts - per Brep (must be Solid) - the BrepFaces (must be 3) and the Planar ones (must be 2). If a Brep fails on these checks (i.e. is not a cylinder or a “cylinder like thing”) then is excluded. If none found the C# terminates. Very simple LINQ stuff in fact. (18.2 KB)

For the general case (any GeometryBase Type [that makes sense - obviously] VS any alignLine) you need an interactive approach - swapping volatile <> persistent data per C# execution (BTW: any slider change is an Event that triggers the C# to execute). As you know GH is not interactive by any means - i.e. can’t deal on the fly with items in collections on a per item basis.

Since the above is maybe tricky to understand I’ll give you an example: assume that you have a flat grid of points. Then assume that you want to pick one (by index) and create a vertical Line with a given Length (where a slider provides the Z value), Then accept or reject the Line … then pick some other pt … or go to a previous created Line and change it … etc etc. By what means can you do it?

That’s doable only via code > pick Brep (by index), then choose ref Face(s) (ditto), then pick alignAxis (also by index) … blah, blah.

1 Like

Thank you guys!
unfortunately I realized more problems with my part of the script and have to investigate what the problem is exactly. I thought the rotation was based on euler - but sometimes it works and sometime it doesn’t with the provided solutions. Sorry, I should have done this earlier

Post a case (or more) where bad things happen.

(Sorry for the late reply, I got sick,)

I’ve tried to figure it out, but still no luck. Here is the actual problem with Tundra Plugin I am facing:
Tundra Is generating Scalar Fields with various pattern and I am trying to align them with the provided curve. Unfortunately the method for rotation is beyond my understanding, I thought it was Euler… (22.3 KB)

Align (having cylinder (or “cylinder like”) Breps in mind) means:

Apply a classic PlaneToPlane trans using 2 Planes: fromPlane is the one defined by the Brep Axis (or some BrepFace Vector [general case as explained above]), toPlane is the one defined by some Vector (in so far the Line.Direction).

Meaning that if you want to Align a Brep VS a Crv … then you should pick some Vector (say: a tangent or some other(*)) related with that Crv (at some param t).

(*) say: use some logic > get pts from Crv and then use some other logic and > get a Vector out of them.

Other that that I don’t work with plug-ins (except K2) and thus I have no idea what Tundra is/does.

Plan B: provide a single test Crv and some explicit - like talking to a very stupid robot - logic/rules for the alignment job. BTW: what sort of stuff are you after? Some artistic thingy? Some freaky building envelope?