Skip to content

@jtopo/core / GeomUtils

Class: GeomUtils ​

几何顶点(坐标)生成与操作工具类

此类生成的所有顶点坐标均经过归一化([-1, 1])处理。

归一化后的顶点坐标极大地简化了图形变换操作,如缩放、旋转、斜切等。

Since

2.6.0

Table of contents ​

Constructors ​

Methods ​

Constructors ​

constructor ​

new GeomUtils()

Methods ​

getBoundingBox ​

Static getBoundingBox(points): Rectangle

计算一组点的最小外接矩形(Bounding Box)

Parameters ​

NameTypeDescription
pointsPointLike[]点集合

Returns ​

Rectangle

包含所有点的最小矩形


getFirstIntersectPoint ​

Static getFirstIntersectPoint(p1, p2, segPoints, isClosed): Object

Parameters ​

NameType
p1PointLike
p2PointLike
segPointsPointLike[]
isClosedboolean

Returns ​

Object

NameType
xnumber
ynumber

getLineIntersectPoint ​

Static getLineIntersectPoint(p1, p2, p3, p4): Object

Parameters ​

NameType
p1PointLike
p2PointLike
p3PointLike
p4PointLike

Returns ​

Object

NameType
xnumber
ynumber

getLineIntersectPoints ​

Static getLineIntersectPoints(p1, p2, segPoints, isClosed): PointLike[]

Parameters ​

NameType
p1PointLike
p2PointLike
segPointsPointLike[]
isClosedboolean

Returns ​

PointLike[]


isPointInPolygon ​

Static isPointInPolygon(point, polygon): boolean

Parameters ​

NameType
pointPointLike
polygonPointLike[]

Returns ​

boolean


normalizePoints ​

Static normalizePoints(points): { x: number ; y: number }[]

归一化([-1, 1])到一个尺寸为2x2的正方形内

Parameters ​

NameTypeDescription
pointsPointLike[]顶点坐标数组

Returns ​

{ x: number ; y: number }[]

坐标归一化后的坐标数组


pointsToNormalVecs ​

Static pointsToNormalVecs(out, points, isClosed?): void

点坐标转换为法向向量

Parameters ​

NameTypeDescription
outvec2[]-
pointsPointLike[]点坐标数组
isClosed?boolean是否闭合

Returns ​

void

向量数组


rotatePoints ​

Static rotatePoints(normalPoints, angle, cx?, cy?): PointLike[]

旋转点坐标

Parameters ​

NameTypeDescription
normalPointsPointLike[]归一化坐标数组
anglenumber
cx?number旋转中心x坐标,默认为几何原点
cy?number旋转中心y坐标, 默认为几何原点

Returns ​

PointLike[]