Skip to content
On this page

Creating a Cylinder

We can create a cylinder by instantiating an Mx3dMkCylinder object.

You can construct an Mx3dMkCylinder object by providing a right-handed coordinate system (Mx3dGeCSYSR) and the radius and height of the cylinder.

typescript
// Get the document
const doc = mxcad3d.getDocument();
// By default, the constructed right-handed coordinate system is aligned with the world coordinate system
const csysr = new Mx3dGeCSYSR();
// You can set the location of csysr to the world coordinate (5, 5, 5)
csysr.SetLocation(5, 5, 5);
// Create a cylinder with radius 6, height 20, and the base center at (5, 5, 5)
const cylinderMaker = new Mx3dMkCylinder(csysr, 6, 20);
// Get the topological shape
const cylinderShape = cylinderMaker.Shape();
// Create a shape label in the document
const cylinderLabel = doc.addShapeLabel();
// Add the topological shape to the label
cylinderLabel.setShape(cylinderShape);
// Update the display (this will update the model shown in the canvas)
mxcad3d.update();

The constructor of the Mx3dMkCylinder class also has a fourth optional parameter to create an incomplete cylinder, similar to a circular cake with a sector cut off.

typescript
// The interval [0, Math.PI * 3 / 4] around the Z-axis of csysr forms the incomplete cylinder
const cylinderMaker = new Mx3dMkCylinder(csysr, 6, 20, Math.PI * 3 / 4);

Note

GitHub and network connectivity issues may cause slow loading times, so please be patient.