# Class: Vector3

## Table of contents

### Constructors

- constructor

### Properties

- ForwardLH
- ONE
- Phys3D
- Up
- ZERO

### Accessors

- x
- y
- z

### Methods

- abs
- add
- angleTo
- applyMatrix4
- applyMatrix4Raw
- applyQuaternion
- clone
- cross
- distanceTo
- dot
- equal
- fromArray
- fromPhysics
- get
- isZero
- length
- lerp
- negate
- normalize
- print
- scale
- scaleXYZ
- set
- setArray
- setFromArray
- setFromMatrixColumn
- setFromMatrixPosition
- setFromMatrixScale
- setValue
- sub
- toArray
- toPhysics
- transformDirection
- transformDirectionRaw
- clearPhysicsPool
- createFromArray
- createFromNumber
- createFromTypedArray
- fromPhysics
- transformCoordinate
- transformQuat

## Constructors

### constructor

• **new Vector3**(`raw?`, `offset?`)

#### Parameters

| Name | Type |
| :------ | :------ |
| `raw?` | `Float32Array` |
| `offset?` | `number` |

## Properties

### ForwardLH

▪ `Static` `Readonly` **ForwardLH**: [`Vector3`](Vector3)

前方向，基于左手坐标系，不要对该对象进行修改

**`static`**

**`memberof`** Vector3

___

### ONE

▪ `Static` `Readonly` **ONE**: [`Vector3`](Vector3)

一向量，不要对该对象进行修改

**`readonly`**

**`static`**

**`memberof`** Vector3

___

### Phys3D

▪ `Static` `Optional` **Phys3D**: typeof `phys3D`

___

### Up

▪ `Static` `Readonly` **Up**: [`Vector3`](Vector3)

上方向，不要对该对象进行修改

**`static`**

**`memberof`** Vector3

___

### ZERO

▪ `Static` `Readonly` **ZERO**: [`Vector3`](Vector3)

零向量，不要对该对象进行修改

**`readonly`**

**`static`**

**`memberof`** Vector3

## Accessors

### x

• `get` **x**(): `number`

x值

**`memberof`** Vector3

#### Returns

`number`

• `set` **x**(`val`): `void`

x值

#### Parameters

| Name | Type |
| :------ | :------ |
| `val` | `number` |

#### Returns

`void`

___

### y

• `get` **y**(): `number`

y值

**`memberof`** Vector3

#### Returns

`number`

• `set` **y**(`val`): `void`

y值

#### Parameters

| Name | Type |
| :------ | :------ |
| `val` | `number` |

#### Returns

`void`

___

### z

• `get` **z**(): `number`

z值

**`memberof`** Vector3

#### Returns

`number`

• `set` **z**(`val`): `void`

z值

#### Parameters

| Name | Type |
| :------ | :------ |
| `val` | `number` |

#### Returns

`void`

## Methods

### abs

▸ **abs**(): [`Vector3`](Vector3)

#### Returns

[`Vector3`](Vector3)

___

### add

▸ **add**(`v`, `dst?`): [`Vector3`](Vector3)

向量加法

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | [`Vector3`](Vector3) | 目标向量 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### angleTo

▸ **angleTo**(`location`, `dst?`): [`Vector3`](Vector3)

获取到目标点的角度

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `location` | [`Vector3`](Vector3) | 目标点 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### applyMatrix4

▸ **applyMatrix4**(`m`): [`Vector3`](Vector3)

create by janzen
Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.

#### Parameters

| Name | Type |
| :------ | :------ |
| `m` | [`Matrix4`](Matrix4) |

#### Returns

[`Vector3`](Vector3)

___

### applyMatrix4Raw

▸ **applyMatrix4Raw**(`m`): [`Vector3`](Vector3)

create by roamye
Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.

#### Parameters

| Name | Type |
| :------ | :------ |
| `m` | `Float32Array` |

#### Returns

[`Vector3`](Vector3)

___

### applyQuaternion

▸ **applyQuaternion**(`q`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `q` | [`Quaternion`](Quaternion) |

#### Returns

[`Vector3`](Vector3)

___

### clone

▸ **clone**(): [`Vector3`](Vector3)

拷贝该向量

**`memberof`** Vector3

#### Returns

[`Vector3`](Vector3)

拷贝出来的对象

___

### cross

▸ **cross**(`v`, `dst?`): [`Vector3`](Vector3)

向量叉乘

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | [`Vector3`](Vector3) | 目标向量 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### distanceTo

▸ **distanceTo**(`p`): `number`

获取到目标点的距离

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `p` | [`Vector3`](Vector3) | 目标点 |

#### Returns

`number`

计算结果

___

### dot

▸ **dot**(`v`): `number`

向量点乘

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | [`Vector3`](Vector3) | 目标向量 |

#### Returns

`number`

计算结果

___

### equal

▸ **equal**(`v`): `boolean`

判断与目标向量的值是否相等

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | [`Vector3`](Vector3) | 目标向量 |

#### Returns

`boolean`

是否相等，这里误差小于10^-6视为相等

___

### fromArray

▸ **fromArray**(`array`, `offset`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `array` | `Float32Array` |
| `offset` | `number` |

#### Returns

[`Vector3`](Vector3)

___

### fromPhysics

▸ **fromPhysics**(`v`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `v` | `any` |

#### Returns

[`Vector3`](Vector3)

___

### get

▸ **get**(`i`): `number`

#### Parameters

| Name | Type |
| :------ | :------ |
| `i` | `number` |

#### Returns

`number`

___

### isZero

▸ **isZero**(): `boolean`

是否为零向量

**`memberof`** Vector3

#### Returns

`boolean`

___

### length

▸ **length**(): `number`

向量的模

**`memberof`** Vector3

#### Returns

`number`

计算结果

___

### lerp

▸ **lerp**(`v`, `f`, `dst?`): [`Vector3`](Vector3)

在该向量与目标向量之间计算插值

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | [`Vector3`](Vector3) | 目标向量 |
| `f` | `number` | 插值系数 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### negate

▸ **negate**(): [`Vector3`](Vector3)

取反

#### Returns

[`Vector3`](Vector3)

___

### normalize

▸ **normalize**(`dst?`): [`Vector3`](Vector3)

向量归一化

**`memberof`** Vector3

#### Parameters

| Name | Type |
| :------ | :------ |
| `dst?` | [`Vector3`](Vector3) |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### print

▸ **print**(): `void`

#### Returns

`void`

___

### scale

▸ **scale**(`f`, `dst?`): [`Vector3`](Vector3)

向量缩放

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `f` | `number` | 缩放比 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### scaleXYZ

▸ **scaleXYZ**(`x`, `y`, `z`, `dst?`): [`Vector3`](Vector3)

向量缩放

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | `number` | x缩放比 |
| `y` | `number` | y缩放比 |
| `z` | `number` | z缩放比 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### set

▸ **set**(`v`): [`Vector3`](Vector3)

拷贝目标向量的值到该向量

**`memberof`** Vector3

#### Parameters

| Name | Type |
| :------ | :------ |
| `v` | [`Vector3`](Vector3) |

#### Returns

[`Vector3`](Vector3)

自身

___

### setArray

▸ **setArray**(`value`, `offset?`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `value` | `ArrayLike` |
| `offset?` | `number` |

#### Returns

[`Vector3`](Vector3)

___

### setFromArray

▸ **setFromArray**(`xyz`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `xyz` | `number`[] |

#### Returns

[`Vector3`](Vector3)

___

### setFromMatrixColumn

▸ **setFromMatrixColumn**(`m`, `index`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `m` | [`Matrix4`](Matrix4) |
| `index` | `number` |

#### Returns

[`Vector3`](Vector3)

___

### setFromMatrixPosition

▸ **setFromMatrixPosition**(`worldMatrix`): [`Vector3`](Vector3)

create by janzen
Sets this vector to the position elements of the transformation matrix

#### Parameters

| Name | Type |
| :------ | :------ |
| `worldMatrix` | [`Matrix4`](Matrix4) |

#### Returns

[`Vector3`](Vector3)

___

### setFromMatrixScale

▸ **setFromMatrixScale**(`m`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `m` | [`Matrix4`](Matrix4) |

#### Returns

[`Vector3`](Vector3)

___

### setValue

▸ **setValue**(`x`, `y`, `z`): [`Vector3`](Vector3)

设置向量的值

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | `number` | x |
| `y` | `number` | y |
| `z` | `number` | z |

#### Returns

[`Vector3`](Vector3)

自身

___

### sub

▸ **sub**(`v`, `dst?`): [`Vector3`](Vector3)

向量减法

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | [`Vector3`](Vector3) | 目标向量 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果

___

### toArray

▸ **toArray**(): [`number`, `number`, `number`]

返回向量数据

**`memberof`** Vector3

#### Returns

[`number`, `number`, `number`]

矩阵数据，以JSArray返回

___

### toPhysics

▸ **toPhysics**(): `any`

created by shanexyzhou
生成物理引擎内的RawVec3f

#### Returns

`any`

___

### transformDirection

▸ **transformDirection**(`m`): [`Vector3`](Vector3)

create by janzen
Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and then normalizes the result.

#### Parameters

| Name | Type |
| :------ | :------ |
| `m` | [`Matrix4`](Matrix4) |

#### Returns

[`Vector3`](Vector3)

___

### transformDirectionRaw

▸ **transformDirectionRaw**(`raw`): [`Vector3`](Vector3)

create by roamye
Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and then normalizes the result.

#### Parameters

| Name | Type |
| :------ | :------ |
| `raw` | `Float32Array` |

#### Returns

[`Vector3`](Vector3)

___

### clearPhysicsPool

▸ `Static` **clearPhysicsPool**(): `void`

#### Returns

`void`

___

### createFromArray

▸ `Static` **createFromArray**(`array`): [`Vector3`](Vector3)

使用一个数组创建
此操作会拷贝一份数组

**`static`**

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `array` | `number`[] | 数据源，长度必须为3，否则会抛出异常 |

#### Returns

[`Vector3`](Vector3)

创建出来的向量

___

### createFromNumber

▸ `Static` **createFromNumber**(`x`, `y`, `z`): [`Vector3`](Vector3)

使用数值创建
推荐使用这种方式代替new Vector3

**`static`**

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | `number` | x |
| `y` | `number` | y |
| `z` | `number` | z |

#### Returns

[`Vector3`](Vector3)

创建出来的向量

___

### createFromTypedArray

▸ `Static` **createFromTypedArray**(`array`, `offset?`): [`Vector3`](Vector3)

使用某个已有的typedArray创建
此操作不会拷贝数据，而是在原来的内存区域上操作

**`static`**

**`memberof`** Vector3

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `array` | `Float32Array` | `undefined` | 数据源 |
| `offset` | `number` | `0` | - |

#### Returns

[`Vector3`](Vector3)

___

### fromPhysics

▸ `Static` **fromPhysics**(`v`): [`Vector3`](Vector3)

created by shanexyzhou
从物理引擎内的RawVec3f生成Vector3

#### Parameters

| Name | Type |
| :------ | :------ |
| `v` | `any` |

#### Returns

[`Vector3`](Vector3)

___

### transformCoordinate

▸ `Static` **transformCoordinate**(`coordinate`, `transform`, `dst?`): [`Vector3`](Vector3)

#### Parameters

| Name | Type |
| :------ | :------ |
| `coordinate` | [`Vector3`](Vector3) |
| `transform` | [`Matrix4`](Matrix4) |
| `dst?` | [`Vector3`](Vector3) |

#### Returns

[`Vector3`](Vector3)

___

### transformQuat

▸ `Static` **transformQuat**(`source`, `rotation`, `dst?`): [`Vector3`](Vector3)

使用四元数进行向量旋转

**`static`**

**`memberof`** Vector3

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `source` | [`Vector3`](Vector3) | 源向量 |
| `rotation` | [`Quaternion`](Quaternion) | 用于旋转的四元数 |
| `dst?` | [`Vector3`](Vector3) | - |

#### Returns

[`Vector3`](Vector3)

计算结果
