2 transforms after eachother

Hello,

I’m trying to do 2 transforms with a list(of guid), but it will only do the 2nd transform. What am I doing wrong?

For Each item As Guid In GuidList
doc.Objects.Transform(item, Rhino.Geometry.Transform.Mirror(plane), True)
doc.Objects.Transform(item, Rhino.Geometry.Transform.Translation(New Rhino.Geometry.Vector3d(New Rhino.Geometry.Point3d(-centerx, -centery, 0))), True)
Next

You can multiply transforms to get a combined transform. Then only apply the combined transform.

Note that the order in which you multiply matters. For example, translation followed by scaling is different than scaling followed by translation.

Transform t1, t2; //defined elsewhere
Transform combined1 = t1*t2;
Transform combined2 = t2*t1;

// combined1 is usually not the same as combined2
1 Like

I’ve got the 2 lines above.

How do I combine them?

Transform mirror = Rhino.Geometry.Transform.Mirror(plane);
Transform translate = Rhino.Geometry.Transform.Translation(New Rhino.Geometry.Vector3d(New Rhino.Geometry.Point3d(-centerx, -centery, 0));

Transform combined1 = mirror*translate;
Transform combined2 = translate*mirror;
2 Likes

So now I got this:

Dim plane As New Rhino.Geometry.Plane(10, 0, 0, 0)
Dim transform As Geometry.Transform = Rhino.Geometry.Transform.Mirror(plane)
Dim transform2 As Geometry.Transform = Rhino.Geometry.Transform.Translation(New Rhino.Geometry.Vector3d(New Rhino.Geometry.Point3d(-centerx, -centery, 0)))
Dim combined As Geometry.Transform = transform * transform2

For Each item As Guid In GuidList
                    doc.Objects.Transform(item, combined, True)
Next

And still it will only do the last transform. Not move and mirror. But only Move OR mirror

Ow its working. had the old Translation still in the script so it did that double xD
Thanks Menno. Helped me out here :slight_smile:

I have very similar problem with Transformation. I need to transform a selected object continuously in a loop as seen in the attached code. I am running the loop for 18 times and in each loop I am rotating the selected object by 10 degree around z axis ( 0,0,1). But even after doing lots of attempt in different permutation combination, I see only one transformation of 10 degree ( don’t know the first or the last ) where as I expect the selected object to be finally rotated by 180 degree when the loop ends.

What might be issue ?

The code is as below.

public class TransFormTest : Command
{

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        Rhino.DocObjects.ObjRef rhobj1;
        var rc1 = RhinoGet.GetOneObject("Select Link One", true, Rhino.DocObjects.ObjectType.InstanceReference, out rhobj1);
        if (rc1 != Rhino.Commands.Result.Success)
            return rc1;

        currentTransform = Transform.Identity;

        for(int i = 1; i <= 18; i++)
        {
            TransformBrep(ref  doc, rhobj1);
            //Thread.Sleep(100);
        }
        
        return Result.Success;
    }

    public Rhino.Commands.Result TransformBrep(ref  Rhino.RhinoDoc doc, Rhino.DocObjects.ObjRef rhobj1)
    {

        double deg = 10.0;
        double rad = (22.0 / 7.0) / 180.0 * deg;
        Point3d cen = new Point3d(0,0,0);

        Transform xform = Rhino.Geometry.Transform.Rotation(rad, cen);

        currentTransform = currentTransform * xform ;
        //currentTransform = xform * currentTransform; // tried both

        doc.Objects.Transform(rhobj1, currentTransform, true);

        doc.Views.Redraw();  

        return Rhino.Commands.Result.Success;
    }

    Transform currentTransform;

}

No idea. But please use Math.PI and not 22/7 :scream:

1 Like

Solved this problem in an other topic.

After the first transform the rhobj1 reference is lost.
Solution: Use the guid of the object instead of the objref:
doc.Objects.Transform(rhobj1, currentTransform, true);

Meh, 3.0 is good enough for most purposes :slight_smile:

2 Likes

No 3.0 is not good for accurate simulation.

Math.PI is good.

Some times I use 4.0 * Atn(1.0)