跳到主要内容

IDP.Math.KGeomLib 接口

export interface KGeomLib 

KGeomLib类定义了若干方法以方便的执行多种几何建模操作,例如构建曲线、曲面或其他几何算法等。

The KGeometry class defines a number of methods that let you perform different geometric operations, such as creating geometric curves, surfaces, using geometric algorithms, etc.

方法

areCurvesOverlap

areCurvesOverlap(curve1: KCurve3d, curve2: KCurve3d, tolerance?: number): boolean;

在特定容差下,检查两曲线是否有重合部分(包括完全重合)。

Get the overlap status of two curves, include totally and partial overlap.

参数:

  • curve1: KCurve3d

    第一条曲线。

    The first curve.

  • curve2: KCurve3d

    第二条曲线。

    The second curve.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: boolean

如果两条曲线有重合部分,则返回true。

Return true if two curves overlap, otherwise return false.

areCurvesTotallyOverlap

areCurvesTotallyOverlap(curve1: KCurve3d, curve2: KCurve3d, tolerance?: number): boolean;

在特定容差下,检查两曲线是否完全重合。

Get the totally overlap status of two curves with specified tolerance.

参数:

  • curve1: KCurve3d

    第一条曲线。

    The first curve.

  • curve2: KCurve3d

    第二条曲线。

    The second curve.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: boolean

若两条曲线完全重叠,则返回true。

Return true if two curves totally overlap, otherwise return false.

boundedCurve2dInLoop2D

boundedCurve2dInLoop2D(checkCurve: KBoundedCurve2d, baseLoop: KLoop2d, tolerance?: number): KCurveInLoopType;

以特定容差判断轮廓线是否落在另一环内。

Check if bounded curve is inside of base loop2d with specified tolerance.

参数:

  • checkCurve: KBoundedCurve2d

    被判断的轮廓线。

    The bounded curve to check.

  • baseLoop: KLoop2d

    环。

    The base loop2d.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: KCurveInLoopType

返回CurveInLoopType,包含曲线与环的位置关系信息。

The KCurveInLoopType include intersect type.

createAlignCCSMatrix4

createAlignCCSMatrix4(x: KVector3d, y: KVector3d, z: KVector3d, origin: KPoint3d): KMatrix4;

创建一个变换矩阵,是从全局坐标系到局部坐标系的变换。

Create a transformation matrix which align global ccs to the given ccs.

参数:

  • x: KVector3d

    给定坐标系的x方向。

    The x direction of the given coordinate system.

  • y: KVector3d

    给定坐标系的y方向。

    The y direction of the given coordinate system.

  • z: KVector3d

    给定坐标系的z方向。

    The z direction of the given coordinate system.

  • origin: KPoint3d

    给定坐标系的原点。

    The origin of the given coordinate system.

返回值: KMatrix4

变换矩阵。

The transformation matrix.

createArc2dByArcAngle

createArc2dByArcAngle(center: KPoint2d, radius: number, startAngle: number, arcAngle: number): KArc2d;

通过圆弧的圆心、半径、起始角度和圆弧角度来创建一段圆弧。

Create an arc by center, radius, start angle and arc angle.

参数:

  • center: KPoint2d

    圆心。

    The center point of the 2D arc.

  • radius: number

    圆弧半径。

    The radius of the 2D arc.

  • startAngle: number

    圆弧的起始角度。

    The start angle of the arc.

  • arcAngle: number

    圆弧的角度。 正的圆弧角度值表示从圆弧起始角度沿逆时针方向转动这个角度为圆弧终点。 负的圆弧角度值表示从圆弧起始角度沿顺时针方向转动这个角度为圆弧终点。

    The angle of the arc. If the angle is positive, it means the arc span is along the counter clockwise direction. If the angle is negative, it means the arc span is along the clockwise direction.

返回值: KArc2d

二维圆弧。

The 2D arc.

createArc2dByChordAndBulge

createArc2dByChordAndBulge(chord: KLineSegment2d, signedBulge: number): KArc2d;

通过圆弧的弦和圆弧突起的高度比例来创建圆弧。

Create an arc by the chord of the arc and the bulge ratio.

.. . | . . A | . ------------------- chord bulge = Math.tan(A) = sagitta / (0.5 * chord)

NOTE: if signedBulge > 0, the arc is conter clockwise, otherwise it's clockwise.

参数:

  • chord: KLineSegment2d

    圆弧的弦。

    The chord of the 2d arc.

  • signedBulge: number

    圆弧的突起比例。

    The bulge ratio of the arc.

返回值: KArc2d

圆弧。

The 2d arc.

createArc2dByPointsAndStartTangent

createArc2dByPointsAndStartTangent(start: KPoint2d, end: KPoint2d, startTangent: KVector2d, cosTol?: number): KArc2d | null;

通过圆弧起点、终点以及起点切向来创建圆弧。

Create an arc by start point, end point and tangent at start point.

参数:

  • start: KPoint2d

    圆弧起点。

    The start point of the 2d arc.

  • end: KPoint2d

    圆弧终点。

    The end point of the 2d arc.

  • startTangent: KVector2d

    圆弧起点的切向量(单位向量)。 切向量的方向决定了圆弧是逆时针的还是顺时针的。

    The tangent at the start point of the 2d arc. The direction of the tangent determines whether the arc is counter clockwise or clockwise.

  • cosTol: number

    可选参数,用于判断切向量和起点终点之间的连线方向是否平行的容差。如果平行,则返回空。

    The cosin angle tolerance to check whether the tangent is parallel to the direction from start point to end point. If it is parallel, return null.

返回值: KArc2d | null

圆弧。

The 2d arc.

createArc2dByStartEndAngles

createArc2dByStartEndAngles(center: KPoint2d, radius: number, startAngle: number, endAngle: number, isCCW: boolean): KArc2d;

通过圆弧的圆心、半径、起始角度和终止角度来创建一段圆弧。

Create an arc by center, radius, start angle and end angle.

参数:

  • center: KPoint2d

    圆心。

    The center point of the 2D arc.

  • radius: number

    圆弧半径。

    The radius of the 2D arc.

  • startAngle: number

    圆弧的起始角度。

    The start angle of the arc.

  • endAngle: number

    圆弧的终止角度。

    The end angle of the arc.

  • isCCW: boolean

    圆弧是否是逆时针方向。 如果圆弧是逆时针方向,则表示圆弧是圆上从起始角开始沿逆时针方向到达终止角的那一段圆,反之则表示圆上另外一侧的一段。

    Whether the 2d arc is counter clockwise from startAngle to endAngle. True means the counter clockwise segment of the circle from startAngle to endAngle. False means the clockwise segment of the circle from startAngle to endAngle.

返回值: KArc2d

二维圆弧。

The 2D arc.

createArc2dByStartEndPoints

createArc2dByStartEndPoints(center: KPoint2d, startPoint: KPoint2d, endPoint: KPoint2d, isCCW: boolean): KArc2d;

通过圆心、圆弧起点和末点来创建圆弧。

Create an arc by start and end points.

参数:

  • center: KPoint2d

    圆心。

    The center point of the 2D arc.

  • startPoint: KPoint2d

    圆弧的起点,需要注意,该点需要在圆弧上。

    The startPoint point of the 2D arc. The caller need to make sure it's on the arc.

  • endPoint: KPoint2d

    圆弧的末点,需要注意,该点需要在圆弧上。

    The end point of the 2D arc. The caller need to make sure it's on the arc.

  • isCCW: boolean

    圆弧是否是逆时针方向。 如果圆弧是逆时针方向,则表示圆弧是圆上从起点开始沿逆时针方向到达终点的那一段圆,反之则表示圆上另外一侧的一段。

    Whether the 2d arc is counter clockwise from startPoint to endPoint. True means the counter clockwise segment of the circle from startPoint to endPoint. False means the clockwise segment of the circle from startPoint to endPoint.

返回值: KArc2d

二维圆弧。

The 2D arc.

createArc2dByThreePoints

createArc2dByThreePoints(startPoint: KPoint2d, midPoint: KPoint2d, endPoint: KPoint2d): KArc2d | null;

通过三个点创建一个圆弧。 Create an arc by input three points.

参数:

  • startPoint: KPoint2d

    圆弧的起点。

    The start point of the 2D arc.

  • midPoint: KPoint2d

    圆弧的中点。

    The middle point of the 2D arc.

  • endPoint: KPoint2d

    圆弧的末点。

    The end point of the 2D arc.

返回值: KArc2d | null

返回一个圆弧或者null,当三点共线时就是null。

The 2D arc or null (if the three points are colinear).

createArc2dByTwoPointsAndRadius

createArc2dByTwoPointsAndRadius(startPoint: KPoint2d, endPoint: KPoint2d, radius: number, isMinorArc: boolean, isCCW: boolean): KArc2d;

创建给定半径并经过给定起点和终点的圆弧。 当给定圆弧起点、终点和半径之后,总共有4种选择,通过isMinorArc和isCCW两个参数再来决定是哪一种选择。 . . . . . . . .e . . . . . . . . . . . . . . . . . . .s . . . . . . .

Create an arc by start end points and the radius. There will be 4 choices if the start end points and radius of the arc are determined, and the other two parameters isMinorArc and isCCW will determine which one.

参数:

  • startPoint: KPoint2d

    圆弧的起点。

    The startPoint point of the 2D arc.

  • endPoint: KPoint2d

    圆弧的终点。

    The end point of the 2D arc.

  • radius: number

    圆弧半径。 如果半径小于起点和终点之间距离的一半,则取这个距离的一半。也就是圆弧会是经过起点和终点的一个半圆弧。

    The radius of the 2d arc. If radius is smaller than the half distance from startPoint to endPoint, it will return a semicircle arc whose diameter is the distance.

  • isMinorArc: boolean

    当值为true时,表示的是起点和终点之间小的那两段圆弧其中之一。当值为false时,表示的是起点和终点之间大的那两段圆弧其中之一。

    true: minor arc; false: major arc

  • isCCW: boolean

    圆弧是否是逆时针方向。 如果圆弧是逆时针方向,则表示圆弧是圆上从起点开始沿逆时针方向到达终点的那一段圆,反之则表示圆上另外一侧的一段。

    Whether the 2d arc is counter clockwise from startPoint to endPoint. True means the counter clockwise segment of the circle from startPoint to endPoint. False means the clockwise segment of the circle from startPoint to endPoint.

返回值: KArc2d

圆弧。

The 2d arc.

createArc3dByCenterNormalRadius

createArc3dByCenterNormalRadius(center: KPoint3d, normal: KVector3d, radius: number, startPoint: KPoint3d, endPoint: KPoint3d): KArc3d;

通过圆心和法向和半径和起点末点来创建圆弧。 注意:这种方式创建的圆弧始终时围绕着法向逆时针的。

Create an arc by start and end points. NOTE: the created arc is always counter-clockwise around the normal.

参数:

  • center: KPoint3d

    圆心。

    The center point of the 3D arc.

  • normal: KVector3d

    法向。

    The normal of the 3D arc.

  • radius: number

    圆弧半径。

    The radius of the 3D arc.

  • startPoint: KPoint3d

    圆弧的起点,需要注意,该点需要在圆弧上。

    The startPoint point of the 3D arc. The caller need to make sure it's on the arc.

  • endPoint: KPoint3d

    圆弧的末点,需要注意,该点需要在圆弧上。

    The end point of the 3D arc. The caller need to make sure it's on the arc.

返回值: KArc3d

三维圆弧。

The 3D arc.

createArc3dByStartEndAngles

createArc3dByStartEndAngles(center: KPoint3d, xDir: KVector3d, yDir: KVector3d, radius: number, startAngle: number, endAngle: number): KArc3d;

通过圆弧的圆心、X轴、Y轴、半径、起始角度和终止角度来创建一段圆弧。

Create an arc by center, x direction, y direction, radius, start angle and end angle.

参数:

  • center: KPoint3d

    圆心。

    The center point of the 3D arc.

  • xDir: KVector3d

    圆弧局部标架的X轴方向。

    X direction of the arc's local coordinate system, must be normalized.

  • yDir: KVector3d

    圆弧局部标架的Y轴方向。

    Y direction of the arc's local coordinate system, must be normalized.

  • radius: number

    圆弧半径。

    The radius of the 3D arc.

  • startAngle: number

    圆弧的起始角度。

    The start angle of the arc, will be clamped to [0, 2PI).

  • endAngle: number

    圆弧的终止角度。

    The end angle of the arc, will be clamped to [0, 2PI).

返回值: KArc3d

三维圆弧。

The 3D arc.

createArc3dByThreePoints

createArc3dByThreePoints(startPoint: KPoint3d, midPoint: KPoint3d, endPoint: KPoint3d): KArc3d | null;

通过三个点创建一个圆弧。 Create an arc by input three points.

参数:

  • startPoint: KPoint3d

    圆弧的起点。

    The start point of the 3D arc.

  • midPoint: KPoint3d

    圆弧的中点。

    The middle point of the 3D arc.

  • endPoint: KPoint3d

    圆弧的末点。

    The end point of the 3D arc.

返回值: KArc3d | null

返回一个圆弧或者null,当三点共线时就是null。

The 3D arc or null (if the three points are colinear).

createBoundingBox2d

createBoundingBox2d(minPoint: KPoint2d, maxPoint: KPoint2d): KBoundingBox2d;

创建一个KBoundingBox2d对象。

Creates an instance of KBoundingBox2d.

参数:

  • minPoint: KPoint2d

    二维包围盒的左下角点。

    The minimum point of the bounding box.

  • maxPoint: KPoint2d

    二维包围盒的右上顶点。

    The maximum point of the bounding box.

返回值: KBoundingBox2d

包围盒。

The bounding box.

createBoundingBox3d

createBoundingBox3d(minPoint: KPoint3d, maxPoint: KPoint3d): KBoundingBox3d;

创建一个KBoundingBox3d对象。

Creates an instance of KBoundingBox3d.

参数:

  • minPoint: KPoint3d

    三维包围盒的左下角点。

    The minimum point of the bounding box.

  • maxPoint: KPoint3d

    三维包围盒的右上顶点。

    The maximum point of the bounding box.

返回值: KBoundingBox3d

包围盒。

The bounding box.

createCircle2dByCenterAndPoint

createCircle2dByCenterAndPoint(center: KPoint2d, pointOnCircle: KPoint2d): KCircle2d | null;

通过圆心和圆上一点创建一个二维空间的圆。

Create a 2d circle by the origin of the circle and a point on the circle.

参数:

  • center: KPoint2d

    圆心。

    The origin of the circle.

  • pointOnCircle: KPoint2d

    圆上一点。

    A point on the circle.

返回值: KCircle2d | null

返回一个圆,也可能是null(当两点重合时)。

The 2D circle or null if the two points overlap.

createCircle2dByCenterAndRadius

createCircle2dByCenterAndRadius(center: KPoint2d, radius: number): KCircle2d;

通过圆心和半径创建一个二维空间的圆。

Create a 2d circle by the origin and radius.

参数:

  • center: KPoint2d

    圆心。

    Origin of the circle.

  • radius: number

    半径。

    Radius of the circle.

返回值: KCircle2d

返回一个圆。

The 2D circle.

createCircle2dByThreePoints

createCircle2dByThreePoints(startPoint: KPoint2d, midPoint: KPoint2d, endPoint: KPoint2d): KCircle2d | null;

通过三点来创建一圆。

Create an circle by input three points.

参数:

  • startPoint: KPoint2d

    圆上第一个点。

    The start point of the 2D circle.

  • midPoint: KPoint2d

    圆上第二个点。

    The middle point of the 2D circle.

  • endPoint: KPoint2d

    圆上第三个点。

    The end point of the 2D circle.

返回值: KCircle2d | null

返回一个圆,也可能是null(当三点共线时)。

The 2D circle or null (if the three points are colinear).

createCircle3dByCenterNormalRadius

createCircle3dByCenterNormalRadius(center: KPoint3d, normal: KVector3d, radius: number, xDir?: KVector3d): KCircle3d;

通过圆心、半径和法向来创建圆。 注意:创建的圆围绕着·法向时逆时针的。

Create an circle by center, normal, radius. NOTE: the created arc is always counter-clockwise around the normal.

参数:

  • center: KPoint3d

    圆心。

    The center point of the 3D circle.

  • normal: KVector3d

    法向。

    The normal of the 3D circle.

  • radius: number

    半径。

    The radius of the 3D circle.

  • xDir: KVector3d

    圆的X轴方向(可选参数)。

    The X direction of the local coordinate system of the circle.

返回值: KCircle3d

圆。

The 3D circle.

createCircle3dByLCSRadius

createCircle3dByLCSRadius(center: KPoint3d, xDir: KVector3d, yDir: KVector3d, radius: number): KCircle3d;

通过圆心、X轴方向、Y轴方向和半径来创建圆。

Create an circle by origin, direction of X axis, direction of Y axis and radius.

参数:

  • center: KPoint3d

    圆心。

    The origin of the 3D circle.

  • xDir: KVector3d

    圆的X轴方向。

    The direction of the X axis of the circle.

  • yDir: KVector3d

    圆的Y轴方向。

    The direction of the Y axis of the circle.

  • radius: number

    半径。

    The radius of the 3D circle.

返回值: KCircle3d

圆。

The 3D circle.

createCircle3dByThreePoints

createCircle3dByThreePoints(startPoint: KPoint3d, midPoint: KPoint3d, endPoint: KPoint3d): KCircle3d | null;

通过三点来创建一圆。

Create an circle by input three points.

参数:

  • startPoint: KPoint3d

    圆上第一个点。

    The start point of the 3D circle.

  • midPoint: KPoint3d

    圆上第二个点。

    The middle point of the 3D circle.

  • endPoint: KPoint3d

    圆上第三个点。

    The end point of the 3D circle.

返回值: KCircle3d | null

返回一个圆,也可能是null(当三点共线时)。

The 3D circle or null (if the three points are colinear).

createEllipticalArc2dByStartEndParams

createEllipticalArc2dByStartEndParams(center: KPoint2d, xDirection: KVector2d, majorRadius: number, minorRadius: number, startParam: number, endParam: number, isCCW: boolean): KEllipticalArc2d;

通过椭圆心、椭圆长轴方向、椭圆长轴半径、椭圆短轴半径、圆弧起点和末点来创建圆弧。

Create an elliptical arc by center, x direction, major radius, minor radius, start and end points.

参数:

  • center: KPoint2d

    椭圆圆心。

    The center point of the 2D elliptical arc.

  • xDirection: KVector2d

    椭圆长轴方向(X 方向)。

    X direction of the 2D elliptical arc.

  • majorRadius: number

    椭圆长轴半径。

    Major radius of the elliptical arc.

  • minorRadius: number

    椭圆短轴半径。

    Minor radius of the elliptical arc.

  • startParam: number

    椭圆弧的起点参数。

    The start parameter of the 2D arc.

  • endParam: number

    椭圆弧的终点参数。

    The end parameter of the 2D arc.

  • isCCW: boolean

    圆弧是否是逆时针方向。 如果圆弧是逆时针方向,则表示圆弧是圆上从起点开始沿逆时针方向到达终点的那一段圆,反之则表示圆上另外一侧的一段。

    Whether the 2d arc is counter clockwise from startPoint to endPoint. True means the counter clockwise segment of the circle from startPoint to endPoint. False means the clockwise segment of the circle from startPoint to endPoint.

返回值: KEllipticalArc2d

二维椭圆弧。

The 2D arc.

createEllipticalArc2dByStartEndPoints

createEllipticalArc2dByStartEndPoints(center: KPoint2d, xDirection: KVector2d, majorRadius: number, minorRadius: number, startPoint: KPoint2d, endPoint: KPoint2d, isCCW: boolean): KEllipticalArc2d;

通过椭圆心、椭圆长轴方向、椭圆长轴半径、椭圆短轴半径、圆弧起点和末点来创建圆弧。

Create an elliptical arc by center, x direction, major radius, minor radius, start and end points.

参数:

  • center: KPoint2d

    椭圆圆心。

    The center point of the 2D elliptical arc.

  • xDirection: KVector2d

    椭圆长轴方向(X 方向)。

    X direction of the 2D elliptical arc.

  • majorRadius: number

    椭圆长轴半径。

    Major radius of the elliptical arc.

  • minorRadius: number

    椭圆短轴半径。

    Minor radius of the elliptical arc.

  • startPoint: KPoint2d

    椭圆弧的起点,需要注意,该点需要在圆弧上。

    The start point of the 2D arc. The caller need to make sure it's on the arc.

  • endPoint: KPoint2d

    椭圆弧的末点,需要注意,该点需要在圆弧上。

    The end point of the 2D arc. The caller need to make sure it's on the arc.

  • isCCW: boolean

    圆弧是否是逆时针方向。 如果圆弧是逆时针方向,则表示圆弧是圆上从起点开始沿逆时针方向到达终点的那一段圆,反之则表示圆上另外一侧的一段。

    Whether the 2d arc is counter clockwise from startPoint to endPoint. True means the counter clockwise segment of the circle from startPoint to endPoint. False means the clockwise segment of the circle from startPoint to endPoint.

返回值: KEllipticalArc2d

二维椭圆弧。

The 2D arc.

createEuler

createEuler(x?: number, y?: number, z?: number, order?: KEulerOrder): KEuler;

创建一个表示旋转变换的欧拉角对象。

Create an Euler object which represents a rotational transformation.

参数:

  • x: number

    绕x轴旋转角度,默认为0。

    The rotate angle around x axis in radians. Dafault value is 0.

  • y: number

    绕y轴旋转角度,默认为0。

    The rotate angle around y axis in radians. Dafault value is 0.

  • z: number

    绕z轴旋转角度,默认为0。

    The rotate angle around z axis in radians. Dafault value is 0.

  • order: KEulerOrder

    绕x,y,z轴旋转的顺序,包括XYZ,YZX, ZXY, XZY, YXZ, ZYX,默认XYZ。

    The order in which to apply the rotations, including XYZ,YZX, ZXY, XZY, YXZ, ZYX. Dafault value is XYZ.

返回值: KEuler

欧拉角

The euler defining the rotations.

createGeomFace2d

createGeomFace2d(contour: KGeomLoop2d, holes?: KGeomLoop2d[]): KGeomFace2d;

通过内轮廓和外轮廓创建面。 注意:需要保证内轮廓与外轮廓方向相反。

Create a face2d by contour and holes. NOTE: the caller need to make sure the contour and holes have opposite ccw direction

参数:

  • contour: KGeomLoop2d

    面的外轮廓。

    The contour (outer loop) of the face

  • holes: KGeomLoop2d[]

    面的内轮廓。

    The holes (inner loops) of the face.

返回值: KGeomFace2d

返回二维面对象。

Return a face2d object.

createGeomLoop2d

createGeomLoop2d(curves: KBoundedCurve2d[]): KGeomLoop2d;

通过轮廓线数组来创建二维环。 需要保证轮廓线数组首尾相连。

Create a loop2d by bounded curves. The caller need to make sure the input curves are connected tail to head and closed.

参数:

  • curves: KBoundedCurve2d[]

    输入轮廓线数组。

    The input curves of a loop2d.

返回值: KGeomLoop2d

返回二维环对象。

Return a loop2d object.

createGeomLoop2dByPoints

createGeomLoop2dByPoints(points: KPoint2d[]): KGeomLoop2d;

通过点集合来创建二维loop。loop将只含线段。

Create a loop2d by points, the result loop contains only line segments.

参数:

  • points: KPoint2d[]

    环的顶点集合。

    The vertex points of the loop.

返回值: KGeomLoop2d

返回二维环对象。

Return a loop2d object.

createIdentityMatrix3

createIdentityMatrix3(): KMatrix4;

创建一个单位矩阵。

Create an identity matrix.

返回值: KMatrix4

单位矩阵。

The identity matrix.

createIdentityMatrix4

createIdentityMatrix4(): KMatrix4;

创建四阶单位矩阵。

Create an identity matrix.

返回值: KMatrix4

单位矩阵。

The identity matrix.

createInterval

createInterval(start: number, end: number): KInterval;

根据起点和终点创建一个区间。

Create an interval by start and end points.

参数:

  • start: number

    输入区间起点。

    The input start.

  • end: number

    输入区间终点。

    The input end.

返回值: KInterval

返回区间。

Return the interval.

createIntervalFromValues

createIntervalFromValues(values: number[], numTol: number): KInterval;

创建一个包含输入数值的最小区间。

Create an union interval from the input values.

参数:

  • values: number[]

    用于创建区间的数值。

    The values has to be contained by the interval.

  • numTol: number

    用于比较数值大小的容差。

    A tolerance for number comparison.

返回值: KInterval

一个区间。

An interval contains all the values.

createInvalidInterval

createInvalidInterval(): KInterval;

创建一个默认的非法区间。

Create a default invalid interval.

返回值: KInterval

返回区间。

Return interval.

createLine2d

createLine2d(point: KPoint2d, direction: KVector2d): KLine2d;

创建一个KLine2d对象。

Creates an instance of KLine2d.

参数:

  • point: KPoint2d

    二维直线的原点。

    The origin point of the 2D line.

  • direction: KVector2d

    二维直线的方向。

    The direction of the 2D line.

返回值: KLine2d

二维直线。

The 2D line.

createLine3d

createLine3d(point: KPoint3d, direction: KVector3d): KLine3d;

创建一个KLine3d对象。

Creates an instance of KLine3d.

参数:

  • point: KPoint3d

    三维直线的原点。

    The origin point of the 3D line.

  • direction: KVector3d

    三维直线的方向。

    The direction of the 3D line.

返回值: KLine3d

三维直线。

The 3D line.

createLineSegment2d

createLineSegment2d(startPoint: KPoint2d, endPoint: KPoint2d): KLineSegment2d;

创建一个KLineSegment2d对象。

Creates an instance KLineSegment2d

参数:

  • startPoint: KPoint2d

    二维线段的起点。

    The start point of the 2D line segment.

  • endPoint: KPoint2d

    二维线段的终点。

    The end point of the 2D line segment.

返回值: KLineSegment2d

二维线段。

The 2D line segment.

createLineSegment3d

createLineSegment3d(startPoint: KPoint3d, endPoint: KPoint3d): KLineSegment3d;

创建一个KLineSegment3d对象。

Creates an instance KLineSegment3d

参数:

  • startPoint: KPoint3d

    二维线段的起点。

    The start point of the 3D line segment.

  • endPoint: KPoint3d

    二维线段的终点。

    The end point of the 3D line segment.

返回值: KLineSegment3d

三维线段。

The 3D line segment.

createNurbsCurve2d

createNurbsCurve2d(degree: number, knots: number[], controlPoints: KPoint2d[], weights: number[]): KNurbsCurve2d;

通过给定阶数、节点向量、控制点以及权重构建一条非均匀有理样条曲线。

Create a nurbs curve by degree, knots, control points and weights.

参数:

  • degree: number

    阶数。

    The degree of the 2d nurbs curve.

  • knots: number[]

    节点向量。

    The knots of the 2d nurbs curve.

  • controlPoints: KPoint2d[]

    控制顶点。

    The control points of the 2d nurbs curve.

  • weights: number[]

    权重。

    the weights of the 2d nurbs curve.

返回值: KNurbsCurve2d

二维非均匀有理样条曲线。

The 2D nurbs curve.

createPlaneByPointNormal

createPlaneByPointNormal(point: KPoint3d, normal: KVector3d, xDirection?: KVector3d): KPlane;

通过一个点和一个法向来创建平面。

Create a plane from a point and normal.

参数:

  • point: KPoint3d

    平面的原点。

    The origin point of the plane.

  • normal: KVector3d

    平面的法向。

    The normal of the plane.

  • xDirection: KVector3d

    平面的x方向,该参数为可选参数,如给出了,则需要保证是不平行于法向。

    Candidate x direction of the plane, if it's not null, the caller need to make sure it's not parallel to normal.

返回值: KPlane

三维平面。

The 3D plane.

createPlaneByThreePoints

createPlaneByThreePoints(point1: KPoint3d, point2: KPoint3d, point3: KPoint3d): KPlane | null;

通过三点创建一个平面。 平面的原点时第一个点,平面的法向是p1到p2向量与p1到p3向量的叉乘,x轴是p1到p2向量的单位向量。

Create a plane from three points. The generated plane's origin is point1, the normal is the cross production of (point2 - point1) and (point3 - point1), the x axis is (point2 - point1).normalize().

参数:

  • point1: KPoint3d

    输入点p1。

    The input p1.

  • point2: KPoint3d

    输入点p2。

    The input p2.

  • point3: KPoint3d

    输入点p3。

    The input p3.

返回值: KPlane | null

由三点构造的平面,若三点共线则范围null。

The plane constructed by the three points or null (if three points are colinear).

createPoint2d

createPoint2d(x: number, y: number): KPoint2d;

创建一个kpoint2d对象。

Creates an instance of KPoint2d.

参数:

  • x: number

    二维点的x坐标。

    The x value of the 2D point.

  • y: number

    二维点的y坐标。

    The y value of the 2D point.

返回值: KPoint2d

二维点。

The 2D point.

createPoint3d

createPoint3d(x: number, y: number, z: number): KPoint3d;

创建一个kpoint3d对象。

Creates an instance of KPoint3d.

参数:

  • x: number

    三维点的x坐标。

    The x value of the 3D point.

  • y: number

    三维点的y坐标。

    The y value of the 3D point.

  • z: number

    三维点的z坐标。

    The z value of the 3D point.

返回值: KPoint3d

三维点。

The 3D point.

createPolylineCurve2d

createPolylineCurve2d(points: KPoint2d[]): KPolylineCurve2d;

通过点列创建一个二维折线段。

Create a 2D polyline by a list of points.

参数:

  • points: KPoint2d[]

    折线段的顶点序列。

    The vertice of the polyline.

返回值: KPolylineCurve2d

二维折线段。

The 2D polyline.

createPolylineCurve3d

createPolylineCurve3d(points: KPoint3d[]): KPolylineCurve3d;

通过点列创建一个三维折线段。

Create a 3D polyline by a list of points.

参数:

  • points: KPoint3d[]

    折线段的顶点序列。

    The vertice of the polyline.

返回值: KPolylineCurve3d

三维折线段。

The 3D polyline.

createQuaternion

createQuaternion(x?: number, y?: number, z?: number, w?: number): KQuaternion;

创建一个表示旋转变换的四元数对象。

Create a quaternion which represents a rotational transformation.

参数:

  • x: number

    四元数的x虚部,默认为0。

    The quaternion's x value, use 0 by default.

  • y: number

    四元数的y虚部,默认为0。

    The quaternion's y value, use 0 by default.

  • z: number

    四元数的z虚部,默认为0。

    The quaternion's z value, use 0 by default.

  • w: number

    四元数的w实部, 默认为1。

    The quaternion's w value, use 1 by default.

返回值: KQuaternion

四元数

The quaternion defining the rotations.

createRotateMatrix3

createRotateMatrix3(angle: number, center: KPoint2d): KMatrix3;

创建围绕轴旋转的变换矩阵。 旋转轴由一点定义,旋转角度由弧度值给出。

Create an transform matrix that does rotation about an axis. The axis is defined by a point. The angle is given in radians.

参数:

  • angle: number

    旋转角弧度。

    The angle of rotation in radians.

  • center: KPoint2d

    定义旋转轴的点。

    The point to define the axis.

返回值: KMatrix3

旋转变换矩阵。

The rotation transform matrix.

createRotateMatrix4

createRotateMatrix4(angle: number, a: KVector3d, center: KPoint3d): KMatrix4;

创建围绕轴旋转的变换矩阵。 旋转轴由一点和一向量定义,旋转角度由弧度值给出。

Create an transform matrix that does rotation about an axis. The axis is defined by a point and a vector. The angle is given in radians.

参数:

  • angle: number

    旋转角弧度。

    The angle of rotation in radians.

  • a: KVector3d

    用于定义旋转轴的向量。

    The vector to define the axis.

  • center: KPoint3d

    用于定义旋转轴的点。

    The point to define the axis.

返回值: KMatrix4

旋转矩阵。

The rotation transform matrix.

createRotateMatrix4FromEuler

createRotateMatrix4FromEuler(euler: KEuler): KMatrix4;

创建一个由欧拉角定义的旋转变换矩阵。

Create a rotation matrix by the euler angles.

参数:

  • euler: KEuler

    欧拉角和顺序

    The euler angles and order

返回值: KMatrix4

返回旋转矩阵。

Return a rotation matrix.

createRotateMatrix4FromQuaternion

createRotateMatrix4FromQuaternion(q: KQuaternion): KMatrix4;

创建一个由四元数定义的旋转变换矩阵。

Create a rotation matrix by the quaternion.

参数:

  • q: KQuaternion

    四元数

    The quaternion defining the rotations.

返回值: KMatrix4

返回旋转矩阵。

Return a rotation matrix.

createScaleMatrix3

createScaleMatrix3(x: number, y: number): KMatrix3;

创建缩放矩阵。

Create a matrix as scale transform.

参数:

  • x: number

    x方向缩放分量。

    The amount to scale in the X axis.

  • y: number

    y方向缩放分量。

    The amount to scale in the Y axis.

返回值: KMatrix3

缩放矩阵。

The scale transform matrix.

createScaleMatrix4

createScaleMatrix4(x: number, y: number, z: number): KMatrix4;

创建缩放矩阵。

Create a matrix as scale transform.

参数:

  • x: number

    x方向缩放分量。

    The amount to scale in the X axis.

  • y: number

    y方向缩放分量。

    The amount to scale in the Y axis.

  • z: number

    z方向缩放分量。

    The amount to scale in the Z axis.

返回值: KMatrix4

缩放矩阵。

The scale transform matrix.

createTranslationMatrix3

createTranslationMatrix3(x: number, y: number): KMatrix3;

创建平移变换矩阵。

Create an translation transform matrix.

参数:

  • x: number

    x方向平移分量。

    The amount to translate in the X axis.

  • y: number

    y方向平移分量。

    The amount to translate in the Y axis.

返回值: KMatrix3

平移变换矩阵。

The translation transform matrix.

createTranslationMatrix4

createTranslationMatrix4(x: number, y: number, z: number): KMatrix4;

创建平移变换矩阵。

Create an translation transform matrix.

参数:

  • x: number

    x方向平移分量。

    The amount to translate in the X axis.

  • y: number

    y方向平移分量。

    The amount to translate in the Y axis.

  • z: number

    z方向平移分量。

    The amount to translate in the Z axis.

返回值: KMatrix4

平移变换矩阵。

The translation transform matrix.

createVector2d

createVector2d(x: number, y: number): KVector2d;

创建一个kVector2d对象。

Creates an instance of KVector2d

参数:

  • x: number

    二维向量的x分量。

    The x value of the 2D vector

  • y: number

    二维向量的y分量。

    The y value of the 2D vector

返回值: KVector2d

二维向量。

The 2D vector.

createVector3d

createVector3d(x: number, y: number, z: number): KVector3d;

创建一个kVector3d对象。

Creates an instance of KVector3d.

参数:

  • x: number

    三维向量的x分量。

    The x value of the 3D vector.

  • y: number

    三维向量的y分量。

    The y value of the 3D vector.

  • z: number

    三维向量的z分量。

    The z value of the 3D vector.

返回值: KVector3d

三维向量。

The 3D vector.

curve2dsFromJson

curve2dsFromJson(jsonString: string): KCurve2d[];

从Json string中读取curve2d数据并创建相应对象。 加这个接口函数的目的是方便内部写测试用例来测试math apaas接口。 Note: 我们永远不应该加XXXToJson()这样的apaas接口。

Read curve2d data and create corresponding curve2d object from the Json string. The only purpose of adding this api is to add internal test cases more conveniently. Note: We will never add Json writing api like XXXToJson().

参数:

  • jsonString: string

返回值: KCurve2d[]

返回二维曲线对象集合。

Return curve2d objects.

curveIntersectCurve

curveIntersectCurve(curve1: KCurve3d, curve2: KCurve3d, tolerance?: number): KCurvesIntersectRet[];

对两条曲线求交。 如果两曲线完全重合,该方法返回的是空数组。 所以areCurvesTotallyOverlap方法需要在使用该方法之前使用。 对于部分重合的情况,结果是返回重叠的部分的两个端点。

Get the intersection of curve and curve. The method returns an empty array for two completely overlap curves, so the function "areCurvesTotallyOverlap" should be called before calling the interface to determine whether it is completely overlap or not. For two bounding curves, if there is a partial overlap, the return result is two endpoints of the overlap segment.

参数:

  • curve1: KCurve3d

    第一条曲线。

    The first curve.

  • curve2: KCurve3d

    第二条曲线。

    The second curve.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: KCurvesIntersectRet[]

返回是一个KCurvesIntersectRet数组,包含交点信息和重合信息。

The array of KCurvesIntersectRet include status of overlap, intersection point.

curveIntersectSurface

curveIntersectSurface(curve: KCurve3d, surface: KSurface, tolerance?: number): KCurveSurfaceIntersectRet[];

曲线与曲面求交。

Get the intersection of a curve and a surface.

参数:

  • curve: KCurve3d

    求交的曲线。

    The curve to intersect.

  • surface: KSurface

    求交的曲面。

    The surface to intersect.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: KCurveSurfaceIntersectRet[]

返回是一个KCurveSurfaceIntersectRet数组,包含交点信息或者交线信息或重合信息。

The array of KCurveSurfaceIntersectRet include intersect type, intersection point or curve.

faces2dBoolean

faces2dBoolean(faces1: KFace2d[], faces2: KFace2d[], type: KFaceBooleanType): KFaceBooleanRet;

对两组面进行布尔操作。

Calculate the boolean result between blank faces and tool faces.

参数:

  • faces1: KFace2d[]

    第一组面。

    the blank faces

  • faces2: KFace2d[]

    第二组面。

    the tool faces

  • type: KFaceBooleanType

    布尔操作类型。

    the boolean type

返回值: KFaceBooleanRet

返回KFaceBooleanRet,包含布尔结果的面数组和布尔操作是否成功的状态。

The KFaceBooleanRet includes result faces and success status.

intersectIntervals

intersectIntervals(intervals1: KInterval[], intervals2: KInterval[]): KInterval[];

求出两组区间的所有重叠部分。

Get the common parts of the two groups of interval.

参数:

  • intervals1: KInterval[]

    输入区间集合1。

    The input first interval array.

  • intervals2: KInterval[]

    输入区间集合2。

    The input second interval array.

返回值: KInterval[]

返回两组区间的所有重叠部分。

Return the common parts of the two groups of interval.

loop2DInLoop2D

loop2DInLoop2D(checkLoop: KLoop2d, baseLoop: KLoop2d, bIncludeOn?: boolean, tolerance?: number): boolean;

判断环是否落在另一环内。

Check loop2d is inside of base loop2d.

参数:

  • checkLoop: KLoop2d

    被判断的环。

    The check loop2d.

  • baseLoop: KLoop2d

    另一个环。

    The base loop2d.

  • bIncludeOn: boolean

    结果是否包含两环有重叠区域的情况。

    Result include check loop2d is overlap with base loop2d.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: boolean

如果位于环内则返回true。

Return true if inside, otherwise return false.

offsetPath2dWithDistances

offsetPath2dWithDistances(path: KBoundedCurve2d[], deltas: number[], disTol?: number, cosTol?: number): KPath2dOffsetRet;

偏移一组有序的2d曲线,每条曲线的偏移值单独设置 若 delta 大于零,曲线偏移方向为左边;若 delta 小于零,曲线偏移方向为右边 例如:考虑一条逆时针绕向的 path,若 delta 皆大于零,则 path 将向外扩张;若 delta 皆小于零,则 path 将向内收缩

Offset a 2d path with different distances. If the delta > 0, the path will be offset at right side, else if delta < 0, the path will be offset at left side. For example: A CCW path, if delta > 0, the path will be enlarged. if delta < 0, the path will be shrinked.

参数:

  • path: KBoundedCurve2d[]

    输入一组有序的2d曲线集合。

    Input 2d curves in order.

  • deltas: number[]

    输入2d曲线集合对应的偏移量。

    Input each 2d curve offset delta.

  • disTol: number

    输入距离容差,默认1.0e-6。 Input distance tolerance, use 1.0e-6 by default.

  • cosTol: number

    输入角度容差,默认1.0e-6。 Input cosine tolerance, use 1.0e-6 by default.

返回值: KPath2dOffsetRet

返回偏移结果。

Return offset path result.

planeIntersectPlane

planeIntersectPlane(plane1: KPlane, plane2: KPlane, tolerance?: number): KLine3d | null;

两平面求交。

Get the intersection of two planes.

参数:

  • plane1: KPlane

    第一个平面。

    The first plane.

  • plane2: KPlane

    第二个平面。

    The second plane.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: KLine3d | null

返回一条直线,也有可能返回null(当两个平面不相交时)。

A line where the planes intersect if successful. Returns null if the planes do not intersect.

pointInFace2D

pointInFace2D(point: KPoint2d, faceLoops: KFace2d, tolerance?: number): KPtInLoopResult;

以特定容差判断点是否在面中。

Check whether a point is in loops or not with specified tolerance.

参数:

  • point: KPoint2d

    要判断的点。

    The point to compare with the faceLoops.

  • faceLoops: KFace2d

    面是由环数组构成。由二维轮廓线集合组成的环,需要保证环的每一个的末点与下一个的起点时相同的,最后一个的末点与第一个的起点时相同的。 还必须确保环没有自相交。

    face's loops composed by bounded curve2ds, the first bounded curve array is outer loop and other is inner loop. The caller need to make sure each curve's end point is equal to next one's start point, and last curve's end point is equal to the first one's start point. The caller also need to make sure the bounded curve array is not self-intersected.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: KPtInLoopResult

返回KPtInLoopResult,包含点与环的位置关系信息。

The KPtInLoopResult include intersect type, etc.

pointInLoop2D

pointInLoop2D(point: KPoint2d, loop: KLoop2d, tolerance?: number): KPtInLoopResult;

以特定容差检查一点是否在环中。

Check whether a point is in a loop or not with specified tolerance.

参数:

  • point: KPoint2d

    要判断的点。

    The point to compare with the loop.

  • loop: KLoop2d

    由二维轮廓线集合组成的环,需要保证环的每一个的末点与下一个的起点时相同的,最后一个的末点与第一个的起点时相同的。 还必须确保环没有自相交。

    The loop composed by bounded curve2ds. The caller need to make sure each curve's end point is equal to next one's start point, and last curve's end point is equal to the first one's start point. The caller also need to make sure the loop is not self-intersected.

  • tolerance: number

    特定容差,默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: KPtInLoopResult

返回KPtInLoopResult,包含点与环的位置关系信息。

The KPtInLoopResult include intersect type, etc.

slerpFlatQuaternion

slerpFlatQuaternion(q1: number[], offset1: number, q2: number[], offset2: number, t: number): number[];

不同于KQuaternion的slerp函数,这个函数直接基于展平的数组做球面线性插值。

这里我们没有像Math2的Quaternion.slerpFlat函数那样把destination array当作参数传入,让slerp结果直接写到 destination array当中,这是因为如果经过了quickjs虚拟机,那样写入并不能同时改变插件侧的数组对象,修改的 仅仅是math-apaas-impl所在的应用程序侧的数组对象。反过来应用程序“传递”给插件的数组对象,插件可以修改成功, 但是再传回应用程序时,则还是那个没有被改动过的应用程序侧的数组对象。quickjs不能监听对数组的修改去同步两边对应 的数组数据。

Do a slerp operates directly on flat arrays of numbers.

参数:

  • q1: number[]

    输入第一个四元数数组。

    The array representation of the first quaternion.

  • offset1: number

    输入第一个四元数数组的起始索引。

    The offset index in the array where the first quanternion starts.

  • q2: number[]

    输入第二个四元数数组。

    The array representation of the second quaternion.

  • offset2: number

    输入第二个四元数数组的起始索引。

    The offset index in the array where the second quanternion starts.

  • t: number

    输入插值比例。

    Normalized interpolation factor (between 0 and 1).

返回值: number[]

返回数组,存储插值后的四元数[x, y, z, w]。

The array representation of the result quaternion.

uniteIntervals

uniteIntervals(intervals: KInterval[]): KInterval[];

对一组区间中重叠的区间进行合并简化。合并简化后的区间序列和原始区间序列覆盖相同的区域。

Simplify the intervals by uniting the intersected intervals.

参数:

  • intervals: KInterval[]

    输入区间集合。

    The input interval array. 返回合并简化后的区间集合。

    Return the simplified intervals.

返回值: KInterval[]