Hi there,
can someone help me and tell me what is missing from this code below to make the polyline created to rotate?
I am new at coding and can’t find a straight forward way to solve this.
Objective: to rotate polyline created using the points below.
sz = 12;
w = 6;
Point3d[] pts = new Point3d[4];
pts[0] = new Point3d(-sz, (-sz - w), 0);
pts[1] = new Point3d(-sz, -sz, 0);
pts[2] = new Point3d((-sz - w), -sz, 0);
pts[3] = new Point3d((-sz - w), sz, 0);
Polyline PL = new Polyline (pts);
Polyline[] P = new Polyline[4];
P[0] = new Polyline(pts);
Transform tr1 = Transform.Rotation(Math.PI / 2, Vector3d.XAxis, new Point3d(0, 0, 0));
A = PL;
…
thanks in advance.
You create your transformation but you also have to call the transform method on your polyline to transform it. See
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Collections_Point3dList_Transform.htm
Code should look like this:
PL.Transform(tr1);
2 Likes
Additionally, If you are just doing one transform (not making compounds by needing multiple transforms, or not needing the transform multiple times) you can create the transform directly in the execution of the transform.
PL.Transform(Transform.Rotation(Math.PI / 2, Vector3d.XAxis, new Point3d(0, 0, 0)));
Also, be aware that transform does actually transform the reference, so If you needed that polyline anymore you will be acting on the rotated polyline. Good practice is to duplicate geometry you are going to transform (although not always necessary, but good to do if the thing you are going to transform is an input geometry).
Michael, LAndo,
Many thanks. it is ‘clearer’ now.