Math2

Math2

Math2 二维数学对象

Members

Methods

staticAngle(x1,y1,x2,y2) → number

计算点1(x1,y1)到点2(x2,y2)的向量与水平x坐标轴之间的夹角,返回弧度
Name Type Description
x1 number
y1 number
x2 number
y2 number

staticAngleBetween(v0,v1) → number

计算从向量0到向量1之间的张角,逆时针方向为正
Name Type Description
v0 Vector2
v1 Vector2

staticArea(points) → number

计算给定多边形的面积,返回平方米
Name Type Description
points Vector2[] 多边形点数组

staticAreaFromEdge(a,b,c) → number

从三角形三边长度计算给定多边形的面积,返回平方米
Name Type Description
a number 边长1
b number 边长2
c number 边长3

staticBuffer(points,radius,isRoundJoin,isRoundEnd,isClosed) → Vector2[]

计算给点中心线的缓冲区
Name Type Description
points Vector2[] 中心线
radius number 半径米
isRoundJoin boolean optional是否圆角转弯
isRoundEnd boolean optional是否圆角端点
isClosed boolean optional是否闭合

staticBufferPoint(center,radius) → Vector2[]

计算给定点的缓冲区
Name Type Description
radius number 半径,单位米

staticCalcInnerPoint(points,pt) → boolean

计算给定多边形内点
Name Type Description
points Vector2[] 多边形点数组
pt Vector2 结果内点

staticClipLine(polyPoints,linePoints) → Array<Vector2[]>

用多边形裁剪折线
Name Type Description
polyPoints Vector2[] 多边形点
linePoints Vector2[] 折线点

staticClosestPoint(points,pt) → Vector2

计算指定点到折线上最近点的坐标,返回最近点
Name Type Description
points Vector2[] 折线点数组
pt Vector2

staticClosestPointAdvance(points,pt) → PointOnLine

计算指定点到折线上最近点的坐标,返回最近点信息结构
Name Type Description
points Vector2[] 折线点数组
pt Vector2

staticContains(polyPoints,point) → boolean

判断算多边形是否包含指定点
Name Type Description
polyPoints Vector2[] 多边形点数组
point Vector2

staticContainsLine(polyPoints,points) → boolean

判断算多边形是否包含指定折线
Name Type Description
polyPoints Vector2[] 多边形点数组
points Vector2[] 折线点数组

staticContainsRect(polyPoints,rect) → boolean

判断算多边形是否包含指定矩形
Name Type Description
polyPoints Vector2[] 多边形点数组
rect Rect 矩形

staticDistance(x1,y1,x2,y2) → number

计算两对坐标之间距离
Name Type Description
x1 number
y1 number
x2 number
y2 number

staticDistanceLineLine(points1,points2) → number

计算两条折线间距离
Name Type Description
points1 Vector2[]
points2 Vector2[]

staticDistancePoint(pt1,pt2) → number

计算两点间距离
Name Type Description
pt1 Vector2
pt2 Vector2

staticDistancePointLine(point,points) → number

计算点到折线距离
Name Type Description
point Vector2
points Vector2[]

staticIntersectLine(linePoints1,linePoints2) → Array<Vector2[]>

计算折线1被折线2裁剪的结果,返回折线段数组
Name Type Description
linePoints1 Vector2[] 折线1
linePoints2 Vector2[] 折线2

staticIntersectOnePoint(points1,points2,resultPoint) → boolean

计算两条折线的一个交点。如果不相交返回false
Name Type Description
points1 Vector2[]
points2 Vector2[]
resultPoint Vector2 交点坐标

staticIntersects(linePoints1,linePoints2) → boolean

判断两条折线是否相交
Name Type Description
linePoints1 Vector2[] 折线1
linePoints2 Vector2[] 折线2

staticIntersectSegment(x1,y1,x2,y2,x3,y3,x4,y4,resultPoint) → boolean

判断两个线段是否相交
Name Type Description
x1 number 线段1起点x坐标
y1 number 线段1起点y坐标
x2 number 线段1终点x坐标
y2 number 线段1终点y坐标
x3 number 线段2起点x坐标
y3 number 线段2起点y坐标
x4 number 线段2终点x坐标
y4 number 线段2终点y坐标
resultPoint Vector2 如果相交,则保存相交点坐标

staticIntersectSegmentPoint(pt1,pt2,pt3,pt4,resultPoint) → boolean

判断两个线段是否相交
Name Type Description
pt1 Vector2 线段1起点
pt2 Vector2 线段1终点
pt3 Vector2 线段2起点
pt4 Vector2 线段2终点
resultPoint Vector2 如果相交,则保存相交点坐标

staticLength(points) → number

计算折线长度
Name Type Description
points Vector2[] 折线点数组

staticNearEqual(pt1,pt2,tolerance) → boolean

判断两个二维点是否近似相等
Name Type Description
pt1 Vector2 点1
pt2 Vector2 点2
tolerance number optional容差

staticNearEqualRect(rect1,rect2,tolerance) → boolean

判断两个矩形是否近似相等
Name Type Description
rect1 Rect 矩形1
rect2 Rect 矩形2
tolerance number optional容差

staticOverlaps(polyPoints1,polyPoints2) → boolean

判断两个多边形是否有重合范围
Name Type Description
polyPoints1 Vector2[] 多边形1
polyPoints2 Vector2[] 多边形2

staticRectContains(outerRect,innerRect) → boolean

判断第一个矩形是否包含第二个
Name Type Description
outerRect Rect 外部矩形
innerRect Rect 内部矩形

staticRectIntersects(rect1,rect2) → boolean

判断两个矩形是否相交
Name Type Description
rect1 Rect 矩形1
rect2 Rect 矩形2

staticRectIntersectsLine(rect,points) → boolean

判断矩形是否与折线相交
Name Type Description
rect Rect 矩形
points Vector2[] 折线点数组

staticRectWithin(rect,center,radius) → boolean

判断指定中心点半径的圆是否被矩形包含
Name Type Description
rect Rect 矩形
center Vector2 中心点
radius number 半径

staticSquareDistance(x1,y1,x2,y2) → number

两点之间的平方距离,及(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)。用于快速的裁剪或者排序判断,不需要做开平方运算
Name Type Description
x1 number
y1 number
x2 number
y2 number

staticSquareDistancePoint(pt1,pt2) → number

两点之间的平方距离
Name Type Description
pt1 Vector2
pt2 Vector2