Skip to content
On this page

mxcad3d具备绘制常见的基本曲面的能力,以下是绘制基本曲面的示例代码。

平面

typescript
// 平面经过的一点
const pt = new Mx3dGePoint(0, 0, 0);
// 平面的法向量
const dir = new Mx3dGeDir(0, 0, 1);
// 参数几何平面
const plane = new Mx3dGeomPlane(pt, dir);
// UV参数范围[0, 100],[0, 100],精度1e-5
const planeFace = plane.Face(0, 100, 0, 100, 1e-5);
// 形状添加至文档
addShapeToDoc(planeFace);
// 更新显示(会更新canvas中显示的模型)
mxcad3d.update();

圆柱面

typescript
const csysr = new Mx3dGeCSYSR();
const cylinderMaker = new Mx3dMkCylinder(csysr, 15, 60, Math.PI * 3 / 2);
const cylinderFace = cylinderMaker.Face();
addShapeToDoc(cylinderFace);
mxcad3d.update();

圆锥面

typescript
const csysr = new Mx3dGeCSYSR();
const coneMaker = new Mx3dMkCone(csysr, 15, 5, 50, Math.PI * 3 / 2);
const coneFace = coneMaker.Face();
addShapeToDoc(coneFace);
mxcad3d.update();

球面

typescript
const csysr = new Mx3dGeCSYSR();
const sphereMaker = new Mx3dMkSphere(csysr, 15, Math.PI * 3 / 2);
const sphereFace = sphereMaker.Face();
addShapeToDoc(sphereFace);
mxcad3d.update();

圆环面

typescript
const csysr = new Mx3dGeCSYSR();
const torusMaker = new Mx3dMkTorus(csysr, 13, 2, Math.PI / 2);
const torusFace = torusMaker.Face();
addShapeToDoc(torusFace);
mxcad3d.update();

B样条曲面

typescript
const pt1 = new Mx3dGePoint(0, 0, 0);
const pt2 = new Mx3dGePoint(0, 100, 20);
const pt3 = new Mx3dGePoint(0, 200, 100);
const pt4 = new Mx3dGePoint(0, 300, 0);
const pt5 = new Mx3dGePoint(100, 0, 50);
const pt6 = new Mx3dGePoint(100, 100, 30);
const pt7 = new Mx3dGePoint(100, 200, 200);
const pt8 = new Mx3dGePoint(100, 300, 0);
// 控制点
const Poles = [[pt1, pt2, pt3, pt4],[pt5, pt6, pt7, pt8]];
// U节点
const UKnots = [0, 1];
// U重复度
const UMults = [2, 2];
// V节点
const VKnots = [0, 1, 2];
// V重复度
const VMults = [3, 1, 3];
// UV次数1、2,UV周期性false、false
const bSplSurface = new Mx3dGeomBSplineSurface(Poles, UKnots, VKnots, UMults, VMults, 1, 2, false, false);
const bSplSurfaceFace = bSplSurface.Face(1e-5);
addShapeToDoc(bSplSurfaceFace);
mxcad3d.update();

贝塞尔曲面

typescript
const pnt_1_1 = new Mx3dGePoint(10, 10, 10);
const pnt_1_2 = new Mx3dGePoint(20, 10, 15);
const pnt_1_3 = new Mx3dGePoint(30, 10, 20);
const pnt_1_4 = new Mx3dGePoint(40, 10, 15);
const pnt_1_5 = new Mx3dGePoint(50, 10, 10);

const pnt_2_1 = new Mx3dGePoint(10, 20, 15);
const pnt_2_2 = new Mx3dGePoint(20, 20, 20);
const pnt_2_3 = new Mx3dGePoint(30, 20, 15);
const pnt_2_4 = new Mx3dGePoint(40, 20, 10);
const pnt_2_5 = new Mx3dGePoint(50, 20, 15);

const pnt_3_1 = new Mx3dGePoint(10, 30, 10);
const pnt_3_2 = new Mx3dGePoint(20, 30, 15);
const pnt_3_3 = new Mx3dGePoint(30, 30, 20);
const pnt_3_4 = new Mx3dGePoint(40, 30, 15);
const pnt_3_5 = new Mx3dGePoint(50, 30, 10);
// 控制点
const Poles = [[pnt_1_1, pnt_1_2, pnt_1_3, pnt_1_4, pnt_1_5], [pnt_2_1, pnt_2_2, pnt_2_3, pnt_2_4, pnt_2_5], [pnt_3_1, pnt_3_2, pnt_3_3, pnt_3_4, pnt_3_5]];

const bezierSurface = new Mx3dGeomBezierSurface(Poles);
// 精度1e-5
const bezierSurfaceFace = bezierSurface.Face(1e-5);
addShapeToDoc(bezierSurfaceFace);
mxcad3d.update();