algorithmic modeling for Rhino
Hi everyone,
Let's say I have computed a Transform based on the composition of several translations and rotations. And now I would like to apply this Transform to an object, e.g. a Plane, a Curve, a BRep, etc. But instead of applying this transformation in World coordinates, I would like to perform it relative to another Plane's coordinate system. Is there a direct way of doing this directly?
Also, I have noticed the Transform.ChangeBasis(plane p0, plane p1) in C# is inverted? Meaning, p0 is actually target plane and p1 is origin plane? See attached image for this code:
private void RunScript(Plane x, Plane y, Brep z, ref object A, ref object B, ref object C)
{
Transform tt = Transform.ChangeBasis(x, y);
z.Transform(tt);
A = z;
B = tt;
}
Thanks.
JL
Tags:
I think you're looking for PlaneToPlane
http://4.rhino3d.com/5/rhinocommon/?topic=html/M_Rhino_Geometry_Tra...
... and if you want to apply the same transformation in different place :
You have planes :
Dim transAC as rhino.geometry.transform = rhino.geometry.transform.planetoplane(A,C)
B.transform(transAC)
D = B 'just for clarity here
Dim targetTransformation as rhino.geometry.transform = rhino.geometry.transform.planetoplane(C,D)
now the targetTransformation is (I think) the one you asked for.
Sorry for VB, but I think the code is simple enough.
Hi Mateus,
Thanks for your reply. This is close to what I am looking for, but not exactly.
What I am looking for is a way to apply a precalculated Transform to an object, but instead of using World coordinates, using the relative coordinates of a Plane. Let me break it down into an example:
- I have a Transform T (e.g. translating in Z direction one unit).
- I have a reference Plane P (e.g. a XZ plane somewhere in space).
- I have a Geometry G (e.g. a Box).
Now, what I would like to do is to apply Transform T to Geometry G, using Plane P as the coordinate system. In the example above, the box would move one unit in the world -Y direction (which is Plane P's Z direction).
In that case you first compute a PlaneToPlane transformation, and you multiply it with your precalculated transform. Multiplying transform matrices has the effect of combining them, but the order is important (and I can never remember what order is the correct one).
Function OrientTransformation(precomputed as Transform, plane As Plane) As Transform
Dim orient As Transform = Transform.PlaneToPlane(Plane.WorldXY, plane)
Return orient * precomputed
End Function
I didn't test the above code, I'm not sure if the multiplication is in the correct order.
Hi David,
Thanks for your response. The problem with that solution is that the resulting transform also incorporates the change of basis, i.e. the necessary translations + rotations to go from WorldXY to the reference Plane.
What I am looking for is using the target Plane just as a reference, and if the Transform is a for example a translation of one unit in Z direction, instead of basing that Transform on World coordinates, using the Plane's position and orientation for this Transform. Maybe what I am asking doesn't make sense algebraically, I am not sure anymore...
Let me create an example of what I am looking at and post it here.
Here goes an example of what I am trying to achieve, but with Translation transforms implemented only.
You just need to apply the inverse Plane to Plane transformation afterwards, i.e
T' = A*T*Ainv
Or in c# (also attached):
Transform p2p = Transform.PlaneToPlane(Plane.WorldXY, plane);
Transform p2pI;
p2p.TryGetInverse(out p2pI);geo.Transform(p2p);
geo.Transform(xform);
geo.Transform(p2pI);A = geo;
Multiplying those transforms before applying them will reduce computation time...
Ok, so that's what matrix similarity means in geometrical terms... Nice!
http://en.wikipedia.org/wiki/Matrix_similarity
I would add to this that, if the Transformation matrix only includes rotations and translations, a faster implementation of the inverse matrix can be applied by doing
Ainv = [ Rt, -Rt*d; 0, 1]
where Rt is the transpose of the 3x3 rotational part and d is the 3x1 translation one.
Thanks a lot Daniel, that was super helpful.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by