Class: Point
Table of contents
Constructors
Properties
Methods
- toJSON
- calculatePointOnMultiPointLine
- createPoints
- createPointsBidirectional
- distance
- distancePoint
- forward
- getAngle
- getDistanceSum
- interpolate
- isLikePoint
- looksSame
- mergeClosestPoints
- middle
- offsetWithAngle
- rotate
- rotatePoint
Constructors
constructor
new Point(x?
, y?
)
Parameters
Name | Type | Default value |
---|---|---|
x | number | 0 |
y | number | 0 |
Properties
x
x: number
y
y: number
Methods
toJSON
toJSON(): Object
Returns
Object
Name | Type |
---|---|
x | number |
y | number |
calculatePointOnMultiPointLine
Static
calculatePointOnMultiPointLine(points
, t
): PointLike
计算多点线上某一点的坐标
Parameters
Name | Type | Description |
---|---|---|
points | PointLike [] | 多点坐标数组 |
t | number | 线上某点的相对位置 [0-1] |
Returns
线上某点的坐标
createPoints
Static
createPoints(p
, n
, count?
, includePoint?
): PointLike
[]
创建一组点, 间隔长度为向量n的模(长度)
Parameters
Name | Type | Default value | Description |
---|---|---|---|
p | PointLike | undefined | 起始点 |
n | Vec2 | undefined | 向量数组 |
count | number | 1 | 点的数量,默认为1 |
includePoint | boolean | false | 是否包含起始点,默认为false |
Returns
返回点数组
createPointsBidirectional
Static
createPointsBidirectional(p
, n
, count
): PointLike
[]
Parameters
Name | Type |
---|---|
p | PointLike |
n | Vec2 |
count | number |
Returns
distance
Static
distance(x
, y
, x2
, y2
): number
计算两点之间的距离
Parameters
Name | Type |
---|---|
x | number |
y | number |
x2 | number |
y2 | number |
Returns
number
distancePoint
Static
distancePoint(p1
, p2
): number
计算两点之间的距离
Parameters
Name | Type |
---|---|
p1 | PointLike |
p2 | PointLike |
Returns
number
forward
Static
forward(p
, target
, distance
): Object
Parameters
Name | Type |
---|---|
p | PointLike |
target | PointLike |
distance | number |
Returns
Object
Name | Type |
---|---|
x | number |
y | number |
getAngle
Static
getAngle(a
, z
): number
Parameters
Name | Type |
---|---|
a | PointLike |
z | PointLike |
Returns
number
getDistanceSum
Static
getDistanceSum(points
): number
计算点集合的距离总和
Parameters
Name | Type | Description |
---|---|---|
points | PointLike [] | 点集合 |
Returns
number
返回点集合的距离总和
interpolate
Static
interpolate(a
, b
, t
): PointLike
在给定的两点之间,根据给定的比例t,计算出一个点的坐标
Parameters
Name | Type | Description |
---|---|---|
a | PointLike | 第一个点的坐标 |
b | PointLike | 第二个点的坐标 |
t | number | 比例值,表示在两点之间的位置,0表示a点,1表示b点,0到1之间的值表示两点间的插值点 |
Returns
- 插值点的坐标
isLikePoint
Static
isLikePoint(object
): boolean
Parameters
Name | Type |
---|---|
object | any |
Returns
boolean
looksSame
Static
looksSame(p1
, p2
, e
): boolean
Parameters
Name | Type |
---|---|
p1 | PointLike |
p2 | PointLike |
e | number |
Returns
boolean
mergeClosestPoints
Static
mergeClosestPoints(points
, epsilon?
): PointLike
[]
将一系列的点合并成更少的点,使得相邻的点在某方向上变化不大时仅保留一个点,以减少最终结果中点的数量。
Parameters
Name | Type | Default value | Description |
---|---|---|---|
points | PointLike [] | undefined | |
epsilon | number | Config.PointClosestEpsilon | 参数是判断两个方向是否相近的阈值。 |
Returns
middle
Static
middle(p1
, p2
): Object
Parameters
Name | Type |
---|---|
p1 | PointLike |
p2 | PointLike |
Returns
Object
Name | Type |
---|---|
x | number |
y | number |
offsetWithAngle
Static
offsetWithAngle(p
, angle
, offset
): Object
Parameters
Name | Type |
---|---|
p | PointLike |
angle | number |
offset | EndpointOffset |
Returns
Object
Name | Type |
---|---|
x | number |
y | number |
rotate
Static
rotate(x
, y
, cx
, cy
, angle
): PointLike
点(x,y) 绕点 (x0,y0) 旋转angle后的坐标
Parameters
Name | Type |
---|---|
x | number |
y | number |
cx | number |
cy | number |
angle | number |
Returns
rotatePoint
Static
rotatePoint(p1
, p2
, angle
): Object
旋转点
Parameters
Name | Type |
---|---|
p1 | PointLike |
p2 | PointLike |
angle | number |
Returns
Object
Name | Type |
---|---|
x | number |
y | number |