Skip to content
On this page

Topology shapes have the ability to undergo geometric transformations such as translation, scaling, rotation, and mirroring. Typically, these transformation interfaces are divided into two types: Translate* and Translated*. The former performs the transformation on the calling object itself, while the latter creates a copy of the calling object, performs the transformation on the copy, and then returns the copy.

To keep the code concise, here is a utility function defined to add a shape to the document:

typescript
function addShapeToDoc(theShape: Mx3dShapeObject, color?: Mx3dGeColor){
  // Get the document
  const doc = mxcad3d.getDocument();
  // Add a shape label
  const label = doc.addShapeLabel();
  // Set the shape
  label.setShape(theShape);
  // Set the color
  if(color) label.setColor(color);
}

Translation

typescript
const csysr = new Mx3dGeCSYSR();
csysr.SetLocation(450, 0, 0);
const box = new Mx3dMkBox(csysr, 20, 20, 20);
const boxShape = box.Shape();
const movedBoxShape = boxShape.TranslatedByVec(new Mx3dGeVec(0, 50, 0));
addShapeToDoc(boxShape);
addShapeToDoc(movedBoxShape);
// Update display (will update the model displayed in the canvas)
mxcad3d.update();

Scaling

typescript
const csysr = new Mx3dGeCSYSR();
csysr.SetLocation(500, 0, 0);
const box = new Mx3dMkBox(csysr, 20, 20, 20);
const boxShape = box.Shape();
const movedBoxShape = boxShape.TranslatedByVec(new Mx3dGeVec(0, 50, 0));
movedBoxShape.Scale(new Mx3dGePoint(510, 50, 0), 2);
addShapeToDoc(boxShape);
addShapeToDoc(movedBoxShape);
// Update display (will update the model displayed in the canvas)
mxcad3d.update();

Rotation

typescript
const csysr = new Mx3dGeCSYSR();
csysr.SetLocation(550, 0, 0);
const box = new Mx3dMkBox(csysr, 20, 20, 20);
const boxShape = box.Shape();
const movedBoxShape = boxShape.TranslatedByVec(new Mx3dGeVec(0, 50, 0));
const axis = new Mx3dGeAxis(new Mx3dGePoint(560, 60, 0), new Mx3dGeDir(0, 0, 1));
movedBoxShape.Rotate(axis, Math.PI / 4);
addShapeToDoc(boxShape);
addShapeToDoc(movedBoxShape);
// Update display (will update the model displayed in the canvas)
mxcad3d.update();

Mirroring

typescript
const csysr = new Mx3dGeCSYSR();
csysr.SetLocation(600, 0, 0);
const box = new Mx3dMkBox(csysr, 20, 20, 20);
const boxShape = box.Shape();
const axis = new Mx3dGeAxis(new Mx3dGePoint(615, 30, 0), new Mx3dGeDir(0, 0, 1));
const mirroredBoxShape = boxShape.MirroredByAxis(axis);
addShapeToDoc(boxShape);
addShapeToDoc(mirroredBoxShape);
// Update display (will update the model displayed in the canvas)
mxcad3d.update();