[gs-longan](../README.md) / GeometryOperators

# Class: GeometryOperators

常用几何运算函数集合（单精度）

提供线线求交、点到线/平面投影、多边形相关判断、距离与角度计算等工具函数。

## Table of contents

### Constructors

- [constructor](GeometryOperators.md#constructor)

### Methods

- [IsParallel](GeometryOperators.md#isparallel)
- [angleBetween](GeometryOperators.md#anglebetween)
- [angleBetweenByNormal](GeometryOperators.md#anglebetweenbynormal)
- [angleToRadian](GeometryOperators.md#angletoradian)
- [closestPoint](GeometryOperators.md#closestpoint)
- [createRingPoints](GeometryOperators.md#createringpoints)
- [distance](GeometryOperators.md#distance)
- [distancePoint](GeometryOperators.md#distancepoint)
- [includeAngleBetween](GeometryOperators.md#includeanglebetween)
- [intersectionLineLine](GeometryOperators.md#intersectionlineline)
- [intersectionLineLine1](GeometryOperators.md#intersectionlineline1)
- [intersectionLinePlane](GeometryOperators.md#intersectionlineplane)
- [intersectionLineSegmentLineSegment](GeometryOperators.md#intersectionlinesegmentlinesegment)
- [intersectionLineSegmentPlane](GeometryOperators.md#intersectionlinesegmentplane)
- [inversePolygon](GeometryOperators.md#inversepolygon)
- [isParallel](GeometryOperators.md#isparallel-1)
- [isPerpendicular](GeometryOperators.md#isperpendicular)
- [isPointInLineSegment](GeometryOperators.md#ispointinlinesegment)
- [isPointInPolygonXy](GeometryOperators.md#ispointinpolygonxy)
- [isPointOnPolygonXy](GeometryOperators.md#ispointonpolygonxy)
- [lineParam](GeometryOperators.md#lineparam)
- [lineParam1](GeometryOperators.md#lineparam1)
- [polygonNormal](GeometryOperators.md#polygonnormal)
- [projectPointToLine](GeometryOperators.md#projectpointtoline)
- [projectPointToLine1](GeometryOperators.md#projectpointtoline1)
- [projectPointToLineWithParam](GeometryOperators.md#projectpointtolinewithparam)
- [projectPointToPlane](GeometryOperators.md#projectpointtoplane)
- [reversePoints](GeometryOperators.md#reversepoints)
- [samePoint](GeometryOperators.md#samepoint)
- [sameVector](GeometryOperators.md#samevector)

## Constructors

### constructor

• **new GeometryOperators**(): [`GeometryOperators`](GeometryOperators.md)

#### Returns

[`GeometryOperators`](GeometryOperators.md)

## Methods

### IsParallel

▸ **IsParallel**(`firstDirection`, `secondDirection`): `boolean`

判断两个向量是否平行

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `firstDirection` | `Float32Array` | 第一个方向向量，长度为3的Float32Array数组 [x, y, z] |
| `secondDirection` | `Float32Array` | 第二个方向向量，长度为3的Float32Array数组 [x, y, z] |

#### Returns

`boolean`

返回布尔值，true表示两向量平行，false表示不平行

___

### angleBetween

▸ **angleBetween**(`v0`, `v1`): `number`

计算两个向量之间的夹角

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v0` | `Float32Array` | 第一个向量，长度为3的Float32Array数组 [x, y, z] |
| `v1` | `Float32Array` | 第二个向量，长度为3的Float32Array数组 [x, y, z] |

#### Returns

`number`

返回两个向量之间的夹角，单位为弧度，范围在[0, π]之间

___

### angleBetweenByNormal

▸ **angleBetweenByNormal**(`v0`, `v1`, `normal`): `number`

计算两个向量之间的有向夹角，使用法向量确定角度方向

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v0` | `Float32Array` | 第一个向量，长度为3的Float32Array数组 [x, y, z] |
| `v1` | `Float32Array` | 第二个向量，长度为3的Float32Array数组 [x, y, z] |
| `normal` | `Float32Array` | 法向量，用于确定角度的正负方向，长度为3的Float32Array数组 [x, y, z] |

#### Returns

`number`

返回两个向量之间的有向夹角，单位为弧度，范围在[0, 2π]之间

___

### angleToRadian

▸ **angleToRadian**(`angle`): `number`

将角度转换为弧度

#### Parameters

| Name | Type |
| :------ | :------ |
| `angle` | `number` |

#### Returns

`number`

___

### closestPoint

▸ **closestPoint**(`p0`, `v0`, `p1`, `v1`): `any`

计算两条无穷直线（由点 p0,p1 与方向 v0,v1 表示）之间最近点对及参数

#### Parameters

| Name | Type |
| :------ | :------ |
| `p0` | `Float32Array` |
| `v0` | `Float32Array` |
| `p1` | `Float32Array` |
| `v1` | `Float32Array` |

#### Returns

`any`

若平行则返回 null，否则返回 { param0, param1, rp0, rp1 }

___

### createRingPoints

▸ **createRingPoints**(`origin`, `x_axis`, `y_axis`, `paramList`, `length`): `Float32Array`

根据参数生成环形上的点集

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `origin` | `Float32Array` | 环的中心点坐标，长度为3的Float32Array数组 [x, y, z] |
| `x_axis` | `Float32Array` | X轴方向向量，长度为3的Float32Array数组，表示环的X轴方向 |
| `y_axis` | `Float32Array` | Y轴方向向量，长度为3的Float32Array数组，表示环的Y轴方向 |
| `paramList` | `Float32Array` | 参数数组，包含角度参数值（弧度制） |
| `length` | `number` | 环的半径长度 |

#### Returns

`Float32Array`

返回一个Float32Array数组，包含所有生成点的坐标，格式为 [x1, y1, z1, x2, y2, z2, ...]

___

### distance

▸ **distance**(`p1`, `p2`): `number`

计算两点之间的欧氏距离

#### Parameters

| Name | Type |
| :------ | :------ |
| `p1` | `Float32Array` |
| `p2` | `Float32Array` |

#### Returns

`number`

___

### distancePoint

▸ **distancePoint**(`or`, `dir`, `va`): `Float32Array`

根据原点、方向向量和距离值计算新点的坐标

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `or` | `Float32Array` | 原点坐标，长度为3的Float32Array数组，表示三维空间中的起始点(x, y, z) |
| `dir` | `Float32Array` | 方向向量，长度为3的Float32Array数组，表示移动方向(x, y, z) |
| `va` | `number` | 距离值，标量数值，表示沿方向向量移动的距离 |

#### Returns

`Float32Array`

返回一个新的Float32Array数组，包含计算后的新点坐标(x, y, z)

___

### includeAngleBetween

▸ **includeAngleBetween**(`v0`, `v1`): `number`

计算两个向量之间的包含角（锐角）

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v0` | `Float32Array` | 第一个向量，长度为3的Float32Array数组 [x, y, z] |
| `v1` | `Float32Array` | 第二个向量，长度为3的Float32Array数组 [x, y, z] |

#### Returns

`number`

返回两个向量之间的包含角，单位为弧度，范围在[0, π/2]之间

___

### intersectionLineLine

▸ **intersectionLineLine**(`line0_p0`, `line0_p1`, `line1_p0`, `line1_p1`): `any`

计算两条直线的交点（若存在唯一交点）

#### Parameters

| Name | Type |
| :------ | :------ |
| `line0_p0` | `Float32Array` |
| `line0_p1` | `Float32Array` |
| `line1_p0` | `Float32Array` |
| `line1_p1` | `Float32Array` |

#### Returns

`any`

___

### intersectionLineLine1

▸ **intersectionLineLine1**(`line0_point`, `line0_direct`, `line1_point`, `line1_direct`): `any`

与 intersectionLineLine 相似，但使用点+方向向量表示直线

#### Parameters

| Name | Type |
| :------ | :------ |
| `line0_point` | `Float32Array` |
| `line0_direct` | `Float32Array` |
| `line1_point` | `Float32Array` |
| `line1_direct` | `Float32Array` |

#### Returns

`any`

___

### intersectionLinePlane

▸ **intersectionLinePlane**(`line_point`, `line_dir`, `plane_point`, `plane_dir`): \{ `param?`: `undefined` = inter\_param; `pos?`: `undefined` = inter\_point; `res`: `boolean` = false } \| \{ `param`: `number` = line\_param; `pos`: `Float32Array` = result; `res`: `boolean` = true }

计算三维空间中直线与平面的相交点

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `line_point` | `Float32Array` | 直线上的一个点坐标，长度为3的Float32Array数组，表示直线上的参考点(x, y, z) |
| `line_dir` | `Float32Array` | 直线的方向向量，长度为3的Float32Array数组，表示直线的方向(x, y, z) |
| `plane_point` | `Float32Array` | 平面上的一个点坐标，长度为3的Float32Array数组，表示平面上的参考点(x, y, z) |
| `plane_dir` | `Float32Array` | 平面的法向量，长度为3的Float32Array数组，表示垂直于平面的方向向量(x, y, z) |

#### Returns

\{ `param?`: `undefined` = inter\_param; `pos?`: `undefined` = inter\_point; `res`: `boolean` = false } \| \{ `param`: `number` = line\_param; `pos`: `Float32Array` = result; `res`: `boolean` = true }

返回一个对象，包含相交结果信息
         res: 布尔值，表示是否有相交点 (true=有相交点, false=无相交点)
         param: 相交点在直线上的参数值 (仅当res为true时有效)
         pos: 相交点的坐标数组 (仅当res为true时有效)

___

### intersectionLineSegmentLineSegment

▸ **intersectionLineSegmentLineSegment**(`line0_p0`, `line0_p1`, `line1_p0`, `line1_p1`): `any`

计算两条线段是否相交，若相交返回交点位置，否则返回 null

#### Parameters

| Name | Type |
| :------ | :------ |
| `line0_p0` | `Float32Array` |
| `line0_p1` | `Float32Array` |
| `line1_p0` | `Float32Array` |
| `line1_p1` | `Float32Array` |

#### Returns

`any`

___

### intersectionLineSegmentPlane

▸ **intersectionLineSegmentPlane**(`line_start`, `line_end`, `plane_root`, `plane_normal`): \{ `param?`: `undefined` = inter\_param; `pos?`: `undefined` = inter\_point; `res`: `boolean` = false } \| \{ `param`: `any` = inter\_param; `pos`: `any` = inter\_point; `res`: `boolean` = true }

计算线段与平面的交点，返回包含是否相交与交点的对象

#### Parameters

| Name | Type |
| :------ | :------ |
| `line_start` | `Float32Array` |
| `line_end` | `Float32Array` |
| `plane_root` | `Float32Array` |
| `plane_normal` | `Float32Array` |

#### Returns

\{ `param?`: `undefined` = inter\_param; `pos?`: `undefined` = inter\_point; `res`: `boolean` = false } \| \{ `param`: `any` = inter\_param; `pos`: `any` = inter\_point; `res`: `boolean` = true }

___

### inversePolygon

▸ **inversePolygon**(`polygon`): `void`

将多边形的顶点顺序进行逆序排列

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `polygon` | `Float32Array` | 多边形顶点数组，格式为 [x1, y1, z1, x2, y2, z2, ...] 函数会直接修改原数组，无需返回值 |

#### Returns

`void`

___

### isParallel

▸ **isParallel**(`v1`, `v2`): `boolean`

判断两个向量是否平行（考虑容差）

#### Parameters

| Name | Type |
| :------ | :------ |
| `v1` | `Float32Array` |
| `v2` | `Float32Array` |

#### Returns

`boolean`

___

### isPerpendicular

▸ **isPerpendicular**(`v1`, `v2`): `boolean`

判断两个向量是否垂直（考虑容差）

#### Parameters

| Name | Type |
| :------ | :------ |
| `v1` | `Float32Array` |
| `v2` | `Float32Array` |

#### Returns

`boolean`

___

### isPointInLineSegment

▸ **isPointInLineSegment**(`point`, `line_start`, `line_end`): `boolean`

判断点是否在线段上

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要检测的点坐标，长度为3的Float32Array数组 [x, y, z] |
| `line_start` | `Float32Array` | 线段的起始点坐标，长度为3的Float32Array数组 [x1, y1, z1] |
| `line_end` | `Float32Array` | 线段的结束点坐标，长度为3的Float32Array数组 [x2, y2, z2] |

#### Returns

`boolean`

返回布尔值，true表示点在线段上，false表示点不在线段上

___

### isPointInPolygonXy

▸ **isPointInPolygonXy**(`point`, `polygon`): `boolean`

判断点是否在多边形内部（在XY平面上进行判断）

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要检测的点坐标，长度为3的Float32Array数组 [x, y, z] |
| `polygon` | `Float32Array` | 多边形顶点数组，格式为 [x1, y1, z1, x2, y2, z2, ...] |

#### Returns

`boolean`

返回布尔值，true表示点在多边形内部，false表示点在多边形外部

___

### isPointOnPolygonXy

▸ **isPointOnPolygonXy**(`point`, `polygon_points`, `polygon_indexes`): `boolean`

判断点是否在多边形的边界上（在XY平面上进行判断）

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要检测的点坐标，长度为3的Float32Array数组 [x, y, z] |
| `polygon_points` | `Float32Array` | 多边形的所有顶点坐标数组，格式为 [x1, y1, z1, x2, y2, z2, ...] |
| `polygon_indexes` | `Int32Array` | 多边形索引数组，用于定义多边形的各个子多边形 每个子多边形由一个数字n和n个索引组成，n表示该子多边形的顶点数量 |

#### Returns

`boolean`

返回布尔值，true表示点在多边形边界上，false表示点不在多边形边界上

___

### lineParam

▸ **lineParam**(`point`, `origin`, `direction`): `number`

计算点相对于直线上参考点的位置参数

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要计算参数的点坐标，长度为3的Float32Array数组 [x, y, z] |
| `origin` | `Float32Array` | 直线上的参考点坐标，长度为3的Float32Array数组 [x0, y0, z0] |
| `direction` | `Float32Array` | 直线的方向向量，长度为3的Float32Array数组 [dx, dy, dz] |

#### Returns

`number`

返回一个数值，表示点在直线上的参数值
         正值表示点在方向向量的同方向上，负值表示在反方向上

___

### lineParam1

▸ **lineParam1**(`point`, `lineStart`, `lineEnd`): `number`

计算点相对于由两个端点定义的直线上的参数值

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要计算参数的点坐标，长度为3的Float32Array数组 [x, y, z] |
| `lineStart` | `Float32Array` | 直线的起始点坐标，长度为3的Float32Array数组 [x1, y1, z1] |
| `lineEnd` | `Float32Array` | 直线的结束点坐标，长度为3的Float32Array数组 [x2, y2, z2] |

#### Returns

`number`

返回一个数值，表示点在直线上的参数值
         正值表示点在方向向量的同方向上，负值表示在反方向上

___

### polygonNormal

▸ **polygonNormal**(`polygon`): `Float32Array`

计算多边形的法向量

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `polygon` | `Float32Array` | 多边形顶点数组，格式为 [x1, y1, z1, x2, y2, z2, ...] |

#### Returns

`Float32Array`

返回标准化后的法向量数组 [x, y, z]

___

### projectPointToLine

▸ **projectPointToLine**(`point`, `origin`, `direction`): `Float32Array`

将三维空间中的点投影到直线上

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要投影的点坐标，长度为3的Float32Array数组，表示三维空间中的点(x, y, z) |
| `origin` | `Float32Array` | 直线上的参考点坐标，长度为3的Float32Array数组，表示直线上的起始点(x, y, z) |
| `direction` | `Float32Array` | 直线的方向向量，长度为3的Float32Array数组，表示直线的方向(x, y, z) |

#### Returns

`Float32Array`

返回一个新的Float32Array数组，包含投影点的坐标(x, y, z)

___

### projectPointToLine1

▸ **projectPointToLine1**(`point`, `lineStart`, `lineEnd`): `Float32Array`

将三维空间中的点投影到由两个端点定义的直线上

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要投影的点坐标，长度为3的Float32Array数组，表示三维空间中的点(x, y, z) |
| `lineStart` | `Float32Array` | 直线的起始点坐标，长度为3的Float32Array数组，表示直线上的起始点(x, y, z) |
| `lineEnd` | `Float32Array` | 直线的结束点坐标，长度为3的Float32Array数组，表示直线上的结束点(x, y, z) |

#### Returns

`Float32Array`

返回一个新的Float32Array数组，包含投影点的坐标(x, y, z)

___

### projectPointToLineWithParam

▸ **projectPointToLineWithParam**(`point`, `origin`, `direction`): `Object`

将三维空间中的点投影到直线上，并返回投影点位置和参数值

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 要投影的点坐标，长度为3的Float32Array数组，表示三维空间中的点(x, y, z) |
| `origin` | `Float32Array` | 直线上的参考点坐标，长度为3的Float32Array数组，表示直线上的起始点(x, y, z) |
| `direction` | `Float32Array` | 直线的方向向量，长度为3的Float32Array数组，表示直线的方向(x, y, z) |

#### Returns

`Object`

返回一个对象，包含投影点坐标和投影参数
         point: 投影点坐标，长度为3的Float32Array数组
         param: 投影参数，表示投影点相对于直线起始点的位置参数

| Name | Type |
| :------ | :------ |
| `param` | `number` |
| `point` | `Float32Array` |

___

### projectPointToPlane

▸ **projectPointToPlane**(`point`, `root`, `normal`): `Float32Array`

将点投影到平面上并返回投影点

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `point` | `Float32Array` | 待投影点 |
| `root` | `Float32Array` | 平面上一点 |
| `normal` | `Float32Array` | 平面法向 |

#### Returns

`Float32Array`

___

### reversePoints

▸ **reversePoints**(`points`): `number`[]

将三维点数组的顺序进行逆序排列

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `points` | `ArrayLike`\<`number`\> | 点数组，格式为 [x1, y1, z1, x2, y2, z2, ...] |

#### Returns

`number`[]

返回一个新的数组，包含逆序排列后的点坐标

___

### samePoint

▸ **samePoint**(`p0`, `p1`): `boolean`

判断两点是否在容差范围内相等

#### Parameters

| Name | Type |
| :------ | :------ |
| `p0` | `Float32Array` |
| `p1` | `Float32Array` |

#### Returns

`boolean`

___

### sameVector

▸ **sameVector**(`v0`, `v1`): `boolean`

判断两向量是否在法线容差范围内相等

#### Parameters

| Name | Type |
| :------ | :------ |
| `v0` | `Float32Array` |
| `v1` | `Float32Array` |

#### Returns

`boolean`
