Dear Steve and Menno @stevebaer @menno
I am a bit confused about how Matrix Multiplication is implemented here:
http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Transform_Multiply.htm
thanks for the nice explanation of Menno in this post
My question is about the Order the transformation will be combined.
The Documentation claims for xform = A*B
The resulting Transform gives the same result as though you’d first apply A then B.
I think it is the other way round:
->The resulting Transform gives the same result as though you’d first apply B then A.
the following example uses a Translation M (Move) X+100, and a rotation R around the Y-Axis:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
ObjRef[] obj_refs;
var rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs);
if (rc != Result.Success || obj_refs == null)
return rc;
// Translate x+ 100
Transform xFormMove = Transform.Translation(100, 0, 0);
// rotate 30degree arround y-Axis
Transform xFromRotY = Transform.Rotation(Math.PI / 6.0, new Vector3d(0, 1, 0), new Point3d(0, 0, 0));
// combine
Transform xForm_MxR = xFormMove * xFromRotY;
Transform xForm_RxM = xFromRotY * xFormMove;
// check * and Transform.Multiply
Transform xForm_RxM_2 = Transform.Multiply(xFromRotY, xFormMove);
foreach (var obj_ref in obj_refs)
{
Guid newID_MxR;
Guid newID_RxM;
// move * Rotate -> color Red
newID_MxR = doc.Objects.Transform(obj_ref, xForm_MxR,false);
RhinoObject ptMxR = (new ObjRef(newID_MxR)).Object();
ptMxR.Attributes.ColorSource = ObjectColorSource.ColorFromObject;
ptMxR.Attributes.Name = "MxR";
ptMxR.Attributes.ObjectColor = System.Drawing.Color.FromArgb(231, 0, 0);
ptMxR.CommitChanges();
// Rotate * Move -> color green
newID_RxM = doc.Objects.Transform(obj_ref, xForm_RxM, false);
RhinoObject ptRxM = (new ObjRef(newID_RxM)).Object();
ptRxM.Attributes.ColorSource = ObjectColorSource.ColorFromObject;
ptRxM.Attributes.Name = "RxM";
ptRxM.Attributes.ObjectColor = System.Drawing.Color.FromArgb(0, 231, 0);
ptRxM.CommitChanges();
// compare operator vs Method
newID_RxM = doc.Objects.Transform(obj_ref, xForm_RxM_2, false);
RhinoObject ptRxM2 = (new ObjRef(newID_RxM)).Object();
ptRxM2.Attributes.ColorSource = ObjectColorSource.ColorFromObject;
ptRxM2.Attributes.Name = "RxM_2";
ptRxM2.Attributes.ObjectColor = System.Drawing.Color.FromArgb(0, 0, 231);
ptRxM2.CommitChanges();
}
doc.Views.Redraw();
return Result.Success;
}