@lakuna/umath 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/algorithms/combinations.d.ts +2 -0
- package/dist/algorithms/combinations.d.ts.map +1 -0
- package/dist/algorithms/combinations.js +5 -0
- package/dist/algorithms/combinations.js.map +1 -0
- package/dist/algorithms/degreesToRadians.d.ts +2 -0
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -0
- package/dist/algorithms/degreesToRadians.js +4 -0
- package/dist/algorithms/degreesToRadians.js.map +1 -0
- package/dist/algorithms/factorial.d.ts +2 -0
- package/dist/algorithms/factorial.d.ts.map +1 -0
- package/dist/algorithms/factorial.js +4 -0
- package/dist/algorithms/factorial.js.map +1 -0
- package/dist/algorithms/fibonacci.d.ts +2 -0
- package/dist/algorithms/fibonacci.d.ts.map +1 -0
- package/dist/algorithms/fibonacci.js +9 -0
- package/dist/algorithms/fibonacci.js.map +1 -0
- package/dist/algorithms/isPrime.d.ts +2 -0
- package/dist/algorithms/isPrime.d.ts.map +1 -0
- package/dist/algorithms/isPrime.js +12 -0
- package/dist/algorithms/isPrime.js.map +1 -0
- package/dist/algorithms/permutations.d.ts +2 -0
- package/dist/algorithms/permutations.d.ts.map +1 -0
- package/dist/algorithms/permutations.js +5 -0
- package/dist/algorithms/permutations.js.map +1 -0
- package/dist/algorithms/primeFactorization.d.ts +2 -0
- package/dist/algorithms/primeFactorization.d.ts.map +1 -0
- package/dist/algorithms/primeFactorization.js +15 -0
- package/dist/algorithms/primeFactorization.js.map +1 -0
- package/dist/algorithms/radiansToDegrees.d.ts +2 -0
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -0
- package/dist/algorithms/radiansToDegrees.js +4 -0
- package/dist/algorithms/radiansToDegrees.js.map +1 -0
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/linear/DualQuaternion.d.ts +89 -0
- package/dist/linear/DualQuaternion.d.ts.map +1 -0
- package/dist/linear/DualQuaternion.js +530 -0
- package/dist/linear/DualQuaternion.js.map +1 -0
- package/dist/linear/Matrix.d.ts +18 -0
- package/dist/linear/Matrix.d.ts.map +1 -0
- package/dist/linear/Matrix.js +2 -0
- package/dist/linear/Matrix.js.map +1 -0
- package/dist/linear/Matrix2.d.ts +66 -0
- package/dist/linear/Matrix2.d.ts.map +1 -0
- package/dist/linear/Matrix2.js +240 -0
- package/dist/linear/Matrix2.js.map +1 -0
- package/dist/linear/Matrix3.d.ts +91 -0
- package/dist/linear/Matrix3.d.ts.map +1 -0
- package/dist/linear/Matrix3.js +533 -0
- package/dist/linear/Matrix3.js.map +1 -0
- package/dist/linear/Matrix4.d.ts +140 -0
- package/dist/linear/Matrix4.d.ts.map +1 -0
- package/dist/linear/Matrix4.js +1363 -0
- package/dist/linear/Matrix4.js.map +1 -0
- package/dist/linear/Quaternion.d.ts +80 -0
- package/dist/linear/Quaternion.d.ts.map +1 -0
- package/dist/linear/Quaternion.js +371 -0
- package/dist/linear/Quaternion.js.map +1 -0
- package/dist/linear/SquareMatrix.d.ts +7 -0
- package/dist/linear/SquareMatrix.d.ts.map +1 -0
- package/dist/linear/SquareMatrix.js +2 -0
- package/dist/linear/SquareMatrix.js.map +1 -0
- package/dist/linear/Vector.d.ts +30 -0
- package/dist/linear/Vector.d.ts.map +1 -0
- package/dist/linear/Vector.js +2 -0
- package/dist/linear/Vector.js.map +1 -0
- package/dist/linear/Vector2.d.ts +96 -0
- package/dist/linear/Vector2.d.ts.map +1 -0
- package/dist/linear/Vector2.js +293 -0
- package/dist/linear/Vector2.js.map +1 -0
- package/dist/linear/Vector3.d.ts +111 -0
- package/dist/linear/Vector3.d.ts.map +1 -0
- package/dist/linear/Vector3.js +466 -0
- package/dist/linear/Vector3.js.map +1 -0
- package/dist/linear/Vector4.d.ts +86 -0
- package/dist/linear/Vector4.d.ts.map +1 -0
- package/dist/linear/Vector4.js +348 -0
- package/dist/linear/Vector4.js.map +1 -0
- package/dist/types/AxisAngle.d.ts +6 -0
- package/dist/types/AxisAngle.d.ts.map +1 -0
- package/dist/types/AxisAngle.js +2 -0
- package/dist/types/AxisAngle.js.map +1 -0
- package/dist/types/FieldOfView.d.ts +7 -0
- package/dist/types/FieldOfView.d.ts.map +1 -0
- package/dist/types/FieldOfView.js +2 -0
- package/dist/types/FieldOfView.js.map +1 -0
- package/dist/utility/BigNumber.d.ts +1 -1
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +4 -1
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MagnitudeError.d.ts +4 -0
- package/dist/utility/MagnitudeError.d.ts.map +1 -0
- package/dist/utility/MagnitudeError.js +6 -0
- package/dist/utility/MagnitudeError.js.map +1 -0
- package/dist/utility/SingularMatrixError.d.ts +4 -0
- package/dist/utility/SingularMatrixError.d.ts.map +1 -0
- package/dist/utility/SingularMatrixError.js +6 -0
- package/dist/utility/SingularMatrixError.js.map +1 -0
- package/dist/utility/epsilon.d.ts +3 -0
- package/dist/utility/epsilon.d.ts.map +1 -0
- package/dist/utility/epsilon.js +2 -0
- package/dist/utility/epsilon.js.map +1 -0
- package/package.json +15 -7
- package/src/algorithms/combinations.ts +12 -0
- package/src/algorithms/degreesToRadians.ts +10 -0
- package/src/algorithms/factorial.ts +9 -0
- package/src/algorithms/fibonacci.ts +14 -0
- package/src/algorithms/greatestCommonDivisor.ts +2 -2
- package/src/algorithms/isPrime.ts +20 -0
- package/src/algorithms/permutations.ts +12 -0
- package/src/algorithms/primeFactorization.ts +21 -0
- package/src/algorithms/radiansToDegrees.ts +10 -0
- package/src/algorithms/summation.ts +4 -1
- package/src/index.ts +24 -0
- package/src/linear/DualQuaternion.ts +1213 -0
- package/src/linear/Matrix.ts +106 -0
- package/src/linear/Matrix2.ts +709 -0
- package/src/linear/Matrix3.ts +1194 -0
- package/src/linear/Matrix4.ts +2569 -0
- package/src/linear/Quaternion.ts +967 -0
- package/src/linear/SquareMatrix.ts +27 -0
- package/src/linear/Vector.ts +178 -0
- package/src/linear/Vector2.ts +979 -0
- package/src/linear/Vector3.ts +1320 -0
- package/src/linear/Vector4.ts +975 -0
- package/src/types/AxisAngle.ts +10 -0
- package/src/types/FieldOfView.ts +14 -0
- package/src/utility/BigNumber.ts +2 -1
- package/src/utility/MagnitudeError.ts +10 -0
- package/src/utility/SingularMatrixError.ts +13 -0
- package/src/utility/epsilon.ts +2 -0
|
@@ -0,0 +1,1320 @@
|
|
|
1
|
+
import { type Vector, epsilon } from "@lakuna/umath";
|
|
2
|
+
import type { Matrix3Like } from "@lakuna/umath/Matrix3";
|
|
3
|
+
import type { Matrix4Like } from "@lakuna/umath/Matrix4";
|
|
4
|
+
import type { QuaternionLike } from "@lakuna/umath/Quaternion";
|
|
5
|
+
import Quaternion from "@lakuna/umath/Quaternion";
|
|
6
|
+
import { normalize as normalizeVector4, type Vector4Like } from "@lakuna/umath/Vector4";
|
|
7
|
+
|
|
8
|
+
/** A quantity with magnitude and direction in three dimensions. */
|
|
9
|
+
export type Vector3Like = Vector3 | [number, number, number];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a vector with the given values.
|
|
13
|
+
* @param x The first component.
|
|
14
|
+
* @param y The second component.
|
|
15
|
+
* @param z The third component.
|
|
16
|
+
* @param out The vector to store the result in.
|
|
17
|
+
* @returns A new vector.
|
|
18
|
+
*/
|
|
19
|
+
export function fromValues<T extends Vector3Like>(x: number, y: number, z: number, out: T): T {
|
|
20
|
+
out[0] = x;
|
|
21
|
+
out[1] = y;
|
|
22
|
+
out[2] = z;
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Determines whether two vectors are roughly equivalent.
|
|
28
|
+
* @param a The first vector.
|
|
29
|
+
* @param b The second vector.
|
|
30
|
+
* @returns Whether the vectors are equivalent.
|
|
31
|
+
*/
|
|
32
|
+
export function equals(a: Vector3Like, b: Vector3Like): boolean {
|
|
33
|
+
const a0: number = a[0];
|
|
34
|
+
const a1: number = a[1];
|
|
35
|
+
const a2: number = a[2];
|
|
36
|
+
|
|
37
|
+
const b0: number = b[0];
|
|
38
|
+
const b1: number = b[1];
|
|
39
|
+
const b2: number = b[2];
|
|
40
|
+
|
|
41
|
+
return Math.abs(a0 - b0) <= epsilon * Math.max(1, Math.abs(a0), Math.abs(b0))
|
|
42
|
+
&& Math.abs(a1 - b1) <= epsilon * Math.max(1, Math.abs(a1), Math.abs(b1))
|
|
43
|
+
&& Math.abs(a2 - b2) <= epsilon * Math.max(1, Math.abs(a2), Math.abs(b2));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Determines whether two vectors are exactly equivalent.
|
|
48
|
+
* @param a The first vector.
|
|
49
|
+
* @param b The second vector.
|
|
50
|
+
* @returns Whether the vectors are equivalent.
|
|
51
|
+
*/
|
|
52
|
+
export function exactEquals(a: Vector3Like, b: Vector3Like): boolean {
|
|
53
|
+
return a[0] == b[0]
|
|
54
|
+
&& a[1] == b[1]
|
|
55
|
+
&& a[2] == b[2];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Adds two vectors.
|
|
60
|
+
* @param a The augend.
|
|
61
|
+
* @param b The addend.
|
|
62
|
+
* @param out The vector to store the result in.
|
|
63
|
+
* @returns The sum.
|
|
64
|
+
*/
|
|
65
|
+
export function add<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
66
|
+
out[0] = a[0] + b[0];
|
|
67
|
+
out[1] = a[1] + b[1];
|
|
68
|
+
out[2] = a[2] + b[2];
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Copies the values from one vector to another.
|
|
74
|
+
* @param vector The vector to copy.
|
|
75
|
+
* @param out The vector to store the result in.
|
|
76
|
+
* @returns The copy.
|
|
77
|
+
*/
|
|
78
|
+
export function copy<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
79
|
+
out[0] = vector[0];
|
|
80
|
+
out[1] = vector[1];
|
|
81
|
+
out[2] = vector[2];
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Multiplies two vectors.
|
|
87
|
+
* @param a The multiplier.
|
|
88
|
+
* @param b The multiplicand.
|
|
89
|
+
* @param out The vector to store the result in.
|
|
90
|
+
* @returns The product.
|
|
91
|
+
*/
|
|
92
|
+
export function multiply<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
93
|
+
out[0] = a[0] * b[0];
|
|
94
|
+
out[1] = a[1] * b[1];
|
|
95
|
+
out[2] = a[2] * b[2];
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Divides two vectors.
|
|
101
|
+
* @param a The dividend.
|
|
102
|
+
* @param b The divisor.
|
|
103
|
+
* @param out The vector to store the result in.
|
|
104
|
+
* @returns The quotient.
|
|
105
|
+
*/
|
|
106
|
+
export function divide<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
107
|
+
out[0] = a[0] / b[0];
|
|
108
|
+
out[1] = a[1] / b[1];
|
|
109
|
+
out[2] = a[2] / b[2];
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Subtracts two vectors.
|
|
115
|
+
* @param a The minuend.
|
|
116
|
+
* @param b The subtrahend.
|
|
117
|
+
* @param out The vector to store the result in.
|
|
118
|
+
* @returns The difference.
|
|
119
|
+
*/
|
|
120
|
+
export function subtract<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
121
|
+
out[0] = a[0] - b[0];
|
|
122
|
+
out[1] = a[1] - b[1];
|
|
123
|
+
out[2] = a[2] - b[2];
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Rounds up the components of a vector.
|
|
129
|
+
* @param vector The vector.
|
|
130
|
+
* @param out The vector to store the result in.
|
|
131
|
+
* @returns The rounded vector.
|
|
132
|
+
*/
|
|
133
|
+
export function ceil<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
134
|
+
out[0] = Math.ceil(vector[0]);
|
|
135
|
+
out[1] = Math.ceil(vector[1]);
|
|
136
|
+
out[2] = Math.ceil(vector[2]);
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Rounds down the components of a vector.
|
|
142
|
+
* @param vector The vector.
|
|
143
|
+
* @param out The vector to store the result in.
|
|
144
|
+
* @returns The rounded vector.
|
|
145
|
+
*/
|
|
146
|
+
export function floor<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
147
|
+
out[0] = Math.floor(vector[0]);
|
|
148
|
+
out[1] = Math.floor(vector[1]);
|
|
149
|
+
out[2] = Math.floor(vector[2]);
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Rounds the components of a vector.
|
|
155
|
+
* @param vector The vector.
|
|
156
|
+
* @param out The vector to store the result in.
|
|
157
|
+
* @returns The rounded vector.
|
|
158
|
+
*/
|
|
159
|
+
export function round<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
160
|
+
out[0] = Math.round(vector[0]);
|
|
161
|
+
out[1] = Math.round(vector[1]);
|
|
162
|
+
out[2] = Math.round(vector[2]);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Returns the minimum of two vectors.
|
|
168
|
+
* @param a The first vector.
|
|
169
|
+
* @param b The second vector.
|
|
170
|
+
* @param out The vector to store the result in.
|
|
171
|
+
* @returns The minimum.
|
|
172
|
+
*/
|
|
173
|
+
export function min<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
174
|
+
out[0] = Math.min(a[0], b[0]);
|
|
175
|
+
out[1] = Math.min(a[1], b[1]);
|
|
176
|
+
out[2] = Math.min(a[2], b[2]);
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns the maximum of two vectors.
|
|
182
|
+
* @param a The first vector.
|
|
183
|
+
* @param b The second vector.
|
|
184
|
+
* @param out The vector to store the result in.
|
|
185
|
+
* @returns The maximum.
|
|
186
|
+
*/
|
|
187
|
+
export function max<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
188
|
+
out[0] = Math.max(a[0], b[0]);
|
|
189
|
+
out[1] = Math.max(a[1], b[1]);
|
|
190
|
+
out[2] = Math.max(a[2], b[2]);
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Scales a vector by a scalar.
|
|
196
|
+
* @param vector The multiplier.
|
|
197
|
+
* @param scalar The multiplicand.
|
|
198
|
+
* @param out The vector to store the result in.
|
|
199
|
+
* @returns The product.
|
|
200
|
+
*/
|
|
201
|
+
export function scale<T extends Vector3Like>(vector: Vector3Like, scalar: number, out: T): T {
|
|
202
|
+
out[0] = vector[0] * scalar;
|
|
203
|
+
out[1] = vector[1] * scalar;
|
|
204
|
+
out[2] = vector[2] * scalar;
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Adds two vectors after scaling the second by a scalar.
|
|
210
|
+
* @param a The augend.
|
|
211
|
+
* @param b The addend.
|
|
212
|
+
* @param scalar The multiplicand.
|
|
213
|
+
* @param out The vector to store the result in.
|
|
214
|
+
* @returns The sum.
|
|
215
|
+
*/
|
|
216
|
+
export function scaleAndAdd<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, scalar: number, out: T): T {
|
|
217
|
+
out[0] = a[0] + b[0] * scalar;
|
|
218
|
+
out[1] = a[1] + b[1] * scalar;
|
|
219
|
+
out[2] = a[2] + b[2] * scalar;
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Calculates the Euclidean distance between two vectors.
|
|
225
|
+
* @param a The first vector.
|
|
226
|
+
* @param b The second vector.
|
|
227
|
+
* @returns The distance.
|
|
228
|
+
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
229
|
+
*/
|
|
230
|
+
export function distance(a: Vector3Like, b: Vector3Like): number {
|
|
231
|
+
const x: number = b[0] - a[0];
|
|
232
|
+
const y: number = b[1] - a[1];
|
|
233
|
+
const z: number = b[2] - a[2];
|
|
234
|
+
return Math.hypot(x, y, z);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Calculates the squared Euclidean distance between this vector and another.
|
|
239
|
+
* @param a The first vector.
|
|
240
|
+
* @param b The second vector.
|
|
241
|
+
* @returns The squared distance.
|
|
242
|
+
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
243
|
+
*/
|
|
244
|
+
export function squaredDistance(a: Vector3Like, b: Vector3Like): number {
|
|
245
|
+
const x: number = b[0] - a[0];
|
|
246
|
+
const y: number = b[1] - a[1];
|
|
247
|
+
const z: number = b[2] - a[2];
|
|
248
|
+
return x * x + y * y + z * z;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Calculates the magnitude (length) of a vector.
|
|
253
|
+
* @param vector The vector.
|
|
254
|
+
* @returns The magnitude.
|
|
255
|
+
*/
|
|
256
|
+
export function getMagnitude(vector: Vector3Like): number {
|
|
257
|
+
const x: number = vector[0];
|
|
258
|
+
const y: number = vector[1];
|
|
259
|
+
const z: number = vector[2];
|
|
260
|
+
return Math.hypot(x, y, z);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Calculates the squared magnitude (length) of a vector.
|
|
265
|
+
* @param vector The vector.
|
|
266
|
+
* @returns The squared magnitude.
|
|
267
|
+
*/
|
|
268
|
+
export function getSquaredMagnitude(vector: Vector3Like): number {
|
|
269
|
+
const x: number = vector[0];
|
|
270
|
+
const y: number = vector[1];
|
|
271
|
+
const z: number = vector[2];
|
|
272
|
+
return x * x + y * y + z * z;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Negates a vector.
|
|
277
|
+
* @param vector The vector.
|
|
278
|
+
* @param out The vector to store the result in.
|
|
279
|
+
* @returns The negated vector.
|
|
280
|
+
*/
|
|
281
|
+
export function negate<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
282
|
+
out[0] = -vector[0];
|
|
283
|
+
out[1] = -vector[1];
|
|
284
|
+
out[2] = -vector[2];
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Calculates the multiplicative inverse of the components of a vector.
|
|
290
|
+
* @param vector The vector.
|
|
291
|
+
* @param out The vector to store the result in.
|
|
292
|
+
* @returns The inverted vector.
|
|
293
|
+
*/
|
|
294
|
+
export function inverse<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
295
|
+
out[0] = 1 / vector[0];
|
|
296
|
+
out[1] = 1 / vector[1];
|
|
297
|
+
out[2] = 1 / vector[2];
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Normalizes a vector.
|
|
303
|
+
* @param vector The vector.
|
|
304
|
+
* @param out The vector to store the result in.
|
|
305
|
+
* @returns The normalized vector.
|
|
306
|
+
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
307
|
+
*/
|
|
308
|
+
export function normalize<T extends Vector3Like>(vector: Vector3Like, out: T): T {
|
|
309
|
+
const x: number = vector[0];
|
|
310
|
+
const y: number = vector[1];
|
|
311
|
+
const z: number = vector[2];
|
|
312
|
+
|
|
313
|
+
let len: number = x * x + y * y + z * z;
|
|
314
|
+
if (len > 0) {
|
|
315
|
+
len = 1 / Math.sqrt(len);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
out[0] = x * len;
|
|
319
|
+
out[1] = y * len;
|
|
320
|
+
out[2] = z * len;
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Calculates the dot product of two vectors.
|
|
326
|
+
* @param a The multiplier.
|
|
327
|
+
* @param b The multiplicand.
|
|
328
|
+
* @returns The dot product.
|
|
329
|
+
* @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
|
|
330
|
+
*/
|
|
331
|
+
export function dot(a: Vector3Like, b: Vector3Like): number {
|
|
332
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Calculates the cross product of two vectors.
|
|
337
|
+
* @param a The multiplier.
|
|
338
|
+
* @param b The mutliplicand.
|
|
339
|
+
* @param out The vector to store the result in.
|
|
340
|
+
* @returns The cross product.
|
|
341
|
+
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
342
|
+
*/
|
|
343
|
+
export function cross<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
344
|
+
const ax: number = a[0];
|
|
345
|
+
const ay: number = a[1];
|
|
346
|
+
const az: number = a[2];
|
|
347
|
+
|
|
348
|
+
const bx: number = b[0];
|
|
349
|
+
const by: number = b[1];
|
|
350
|
+
const bz: number = b[2];
|
|
351
|
+
|
|
352
|
+
out[0] = ay * bz - az * by;
|
|
353
|
+
out[1] = az * bx - ax * bz;
|
|
354
|
+
out[2] = ax * by - ay * bx;
|
|
355
|
+
return out;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Performs a linear interpolation between two vectors.
|
|
360
|
+
* @param a The first vector.
|
|
361
|
+
* @param b The second vector.
|
|
362
|
+
* @param t The interpolation amount (in `[0,1]`).
|
|
363
|
+
* @param out The vector to store the result in.
|
|
364
|
+
* @returns The interpolated vector.
|
|
365
|
+
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
366
|
+
*/
|
|
367
|
+
export function lerp<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, t: number, out: T): T {
|
|
368
|
+
const ax: number = a[0];
|
|
369
|
+
const ay: number = a[1];
|
|
370
|
+
const az: number = a[2];
|
|
371
|
+
|
|
372
|
+
out[0] = ax + t * (b[0] - ax);
|
|
373
|
+
out[1] = ay + t * (b[1] - ay);
|
|
374
|
+
out[2] = az + t * (b[2] - az);
|
|
375
|
+
return out;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Sets a vector to a random value with the given magnitude.
|
|
380
|
+
* @param magnitude The magnitude.
|
|
381
|
+
* @param out The vector to store the result in.
|
|
382
|
+
* @returns This vector.
|
|
383
|
+
*/
|
|
384
|
+
export function random<T extends Vector3Like>(magnitude: number, out: T): T {
|
|
385
|
+
const r: number = Math.random() * 2 * Math.PI;
|
|
386
|
+
const z: number = Math.random() * 2 - 1;
|
|
387
|
+
const zScale: number = Math.sqrt(1 - z * z) * magnitude;
|
|
388
|
+
|
|
389
|
+
out[0] = Math.cos(r) * zScale;
|
|
390
|
+
out[1] = Math.sin(r) * zScale;
|
|
391
|
+
out[2] = z * magnitude;
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Transforms a vector by a three-by-three matrix.
|
|
397
|
+
* @param vector The vector.
|
|
398
|
+
* @param matrix The matrix.
|
|
399
|
+
* @param out The vector to store the result in.
|
|
400
|
+
* @returns The transformed vector.
|
|
401
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
402
|
+
*/
|
|
403
|
+
export function transformMatrix3<T extends Vector3Like>(vector: Vector3Like, matrix: Matrix3Like, out: T): T {
|
|
404
|
+
const x: number = vector[0];
|
|
405
|
+
const y: number = vector[1];
|
|
406
|
+
const z: number = vector[2];
|
|
407
|
+
|
|
408
|
+
out[0] = x * matrix[0] + y * matrix[3] + z * matrix[6];
|
|
409
|
+
out[1] = x * matrix[1] + y * matrix[4] + z * matrix[7];
|
|
410
|
+
out[2] = x * matrix[2] + y * matrix[5] + z * matrix[8];
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Transforms a vector by a four-by-four matrix.
|
|
416
|
+
* @param vector The vector.
|
|
417
|
+
* @param matrix The matrix.
|
|
418
|
+
* @param out The vector to store the result in.
|
|
419
|
+
* @returns The transformed vector.
|
|
420
|
+
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
421
|
+
*/
|
|
422
|
+
export function transformMatrix4<T extends Vector3Like>(vector: Vector3Like, matrix: Matrix4Like, out: T): T {
|
|
423
|
+
const x: number = vector[0];
|
|
424
|
+
const y: number = vector[1];
|
|
425
|
+
const z: number = vector[2];
|
|
426
|
+
|
|
427
|
+
const w: number = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15] || 1;
|
|
428
|
+
|
|
429
|
+
out[0] = (matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12]) / w;
|
|
430
|
+
out[1] = (matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13]) / w;
|
|
431
|
+
out[2] = (matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]) / w;
|
|
432
|
+
return out;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Rotates a vector around the X-axis.
|
|
437
|
+
* @param vector The vector.
|
|
438
|
+
* @param origin The origin of the rotation.
|
|
439
|
+
* @param radians The angle of rotation in radians.
|
|
440
|
+
* @param out The vector to store the result in.
|
|
441
|
+
* @returns The rotated vector.
|
|
442
|
+
*/
|
|
443
|
+
export function rotateX<T extends Vector3Like>(vector: Vector3Like, origin: Vector3Like, radians: number, out: T): T {
|
|
444
|
+
const p: Vector3Like = [
|
|
445
|
+
vector[0] - origin[0],
|
|
446
|
+
vector[1] - origin[1],
|
|
447
|
+
vector[2] - origin[2]];
|
|
448
|
+
|
|
449
|
+
const r: Vector3Like = [
|
|
450
|
+
p[0],
|
|
451
|
+
p[1] * Math.cos(radians) - p[2] * Math.sin(radians),
|
|
452
|
+
p[1] * Math.sin(radians) + p[2] * Math.cos(radians)];
|
|
453
|
+
|
|
454
|
+
out[0] = r[0] + origin[0];
|
|
455
|
+
out[1] = r[1] + origin[1];
|
|
456
|
+
out[2] = r[2] + origin[2];
|
|
457
|
+
return out;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Rotates a vector around the Y-axis.
|
|
462
|
+
* @param vector The vector.
|
|
463
|
+
* @param origin The origin of the rotation.
|
|
464
|
+
* @param radians The angle of rotation in radians.
|
|
465
|
+
* @param out The vector to store the result in.
|
|
466
|
+
* @returns The rotated vector.
|
|
467
|
+
*/
|
|
468
|
+
export function rotateY<T extends Vector3Like>(vector: Vector3Like, origin: Vector3Like, radians: number, out: T): T {
|
|
469
|
+
const p: Vector3Like = [
|
|
470
|
+
vector[0] - origin[0],
|
|
471
|
+
vector[1] - origin[1],
|
|
472
|
+
vector[2] - origin[2]];
|
|
473
|
+
|
|
474
|
+
const r: Vector3Like = [
|
|
475
|
+
p[2] * Math.sin(radians) + p[0] * Math.cos(radians),
|
|
476
|
+
p[1],
|
|
477
|
+
p[2] * Math.cos(radians) - p[0] * Math.sin(radians)];
|
|
478
|
+
|
|
479
|
+
out[0] = r[0] + origin[0];
|
|
480
|
+
out[1] = r[1] + origin[1];
|
|
481
|
+
out[2] = r[2] + origin[2];
|
|
482
|
+
return out;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Rotates a vector around the Z-axis.
|
|
487
|
+
* @param vector The vector.
|
|
488
|
+
* @param origin The origin of the rotation.
|
|
489
|
+
* @param radians The angle of rotation in radians.
|
|
490
|
+
* @param out The vector to store the result in.
|
|
491
|
+
* @returns The rotated vector.
|
|
492
|
+
*/
|
|
493
|
+
export function rotateZ<T extends Vector3Like>(vector: Vector3Like, origin: Vector3Like, radians: number, out: T): T {
|
|
494
|
+
const p: Vector3Like = [
|
|
495
|
+
vector[0] - origin[0],
|
|
496
|
+
vector[1] - origin[1],
|
|
497
|
+
vector[2] - origin[2]];
|
|
498
|
+
|
|
499
|
+
const r: Vector3Like = [
|
|
500
|
+
p[0] * Math.cos(radians) - p[1] * Math.sin(radians),
|
|
501
|
+
p[0] * Math.sin(radians) + p[1] * Math.cos(radians),
|
|
502
|
+
p[2]];
|
|
503
|
+
|
|
504
|
+
out[0] = r[0] + origin[0];
|
|
505
|
+
out[1] = r[1] + origin[1];
|
|
506
|
+
out[2] = r[2] + origin[2];
|
|
507
|
+
return out;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Gets the angle between two vectors in radians.
|
|
512
|
+
* @param a The first vector.
|
|
513
|
+
* @param b The second vector.
|
|
514
|
+
* @returns The angular distance from the first vector to the second.
|
|
515
|
+
*/
|
|
516
|
+
export function angle(a: Vector3Like, b: Vector3Like): number {
|
|
517
|
+
const ax: number = a[0];
|
|
518
|
+
const ay: number = a[1];
|
|
519
|
+
const az: number = a[2];
|
|
520
|
+
|
|
521
|
+
const bx: number = b[0];
|
|
522
|
+
const by: number = b[1];
|
|
523
|
+
const bz: number = b[2];
|
|
524
|
+
|
|
525
|
+
const mag1: number = Math.sqrt(ax * ax + ay * ay + az * az);
|
|
526
|
+
const mag2: number = Math.sqrt(bx * bx + by * by + bz * bz);
|
|
527
|
+
|
|
528
|
+
const mag: number = mag1 * mag2;
|
|
529
|
+
|
|
530
|
+
const cosine: number = mag && dot(a, b) / mag;
|
|
531
|
+
|
|
532
|
+
return Math.acos(Math.min(Math.max(cosine, -1), 1));
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Sets a vector to the zero vector.
|
|
537
|
+
* @param out The vector to store the result in.
|
|
538
|
+
* @returns This vector.
|
|
539
|
+
*/
|
|
540
|
+
export function zero<T extends Vector3Like>(out: T): T {
|
|
541
|
+
out[0] = 0;
|
|
542
|
+
out[1] = 0;
|
|
543
|
+
out[2] = 0;
|
|
544
|
+
return out;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Performs a Hermite interpolation with two control points between two vectors.
|
|
549
|
+
* @param a The first vector.
|
|
550
|
+
* @param b The first control point.
|
|
551
|
+
* @param c The second control point.
|
|
552
|
+
* @param d The second vector.
|
|
553
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
554
|
+
* @param out The vector to store the result in.
|
|
555
|
+
* @returns The interpolated vector.
|
|
556
|
+
* @see [Hermite interpolation](https://en.wikipedia.org/wiki/Hermite_interpolation)
|
|
557
|
+
*/
|
|
558
|
+
export function hermite<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, c: Vector3Like, d: Vector3Like, t: number, out: T): T {
|
|
559
|
+
const factorTimes2: number = t * t;
|
|
560
|
+
|
|
561
|
+
const factor1: number = factorTimes2 * (2 * t - 3) + 1;
|
|
562
|
+
const factor2: number = factorTimes2 * (t - 2) + t;
|
|
563
|
+
const factor3: number = factorTimes2 * (t - 1);
|
|
564
|
+
const factor4: number = factorTimes2 * (3 - 2 * t);
|
|
565
|
+
|
|
566
|
+
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
567
|
+
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
568
|
+
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
569
|
+
return out;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Performs a Bézier interpolation with two control points between two vectors.
|
|
574
|
+
* @param a The first vector.
|
|
575
|
+
* @param b The first control point.
|
|
576
|
+
* @param c The second control point.
|
|
577
|
+
* @param d The second vector.
|
|
578
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
579
|
+
* @param out The vector to store the result in.
|
|
580
|
+
* @returns The interpolated vector.
|
|
581
|
+
* @see [Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
|
582
|
+
*/
|
|
583
|
+
export function bezier<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, c: Vector3Like, d: Vector3Like, t: number, out: T): T {
|
|
584
|
+
const inverseFactor: number = 1 - t;
|
|
585
|
+
const inverseFactorTimesTwo: number = inverseFactor * inverseFactor;
|
|
586
|
+
const factorTimes2: number = t * t;
|
|
587
|
+
|
|
588
|
+
const factor1: number = inverseFactorTimesTwo * inverseFactor;
|
|
589
|
+
const factor2: number = 3 * t * inverseFactorTimesTwo;
|
|
590
|
+
const factor3: number = 3 * factorTimes2 * inverseFactor;
|
|
591
|
+
const factor4: number = factorTimes2 * t;
|
|
592
|
+
|
|
593
|
+
out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;
|
|
594
|
+
out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;
|
|
595
|
+
out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;
|
|
596
|
+
return out;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Transforms a vector by a quaternion.
|
|
601
|
+
* @param vector The vector.
|
|
602
|
+
* @param quaternion The quaternion.
|
|
603
|
+
* @param out The vector to store the result in.
|
|
604
|
+
* @returns The transformed vector.
|
|
605
|
+
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
606
|
+
*/
|
|
607
|
+
export function transformQuaternion<T extends Vector3Like>(vector: Vector3Like, quaternion: QuaternionLike, out: T): T {
|
|
608
|
+
const qx: number = quaternion[0];
|
|
609
|
+
const qy: number = quaternion[1];
|
|
610
|
+
const qz: number = quaternion[2];
|
|
611
|
+
const qw: number = quaternion[3];
|
|
612
|
+
|
|
613
|
+
const x: number = vector[0];
|
|
614
|
+
const y: number = vector[1];
|
|
615
|
+
const z: number = vector[2];
|
|
616
|
+
|
|
617
|
+
let uvx: number = qy * z - qz * y;
|
|
618
|
+
let uvy: number = qz * x - qx * z;
|
|
619
|
+
let uvz: number = qx * y - qy * x;
|
|
620
|
+
|
|
621
|
+
let uuvx: number = qy * uvz - qz * uvy;
|
|
622
|
+
let uuvy: number = qz * uvx - qx * uvz;
|
|
623
|
+
let uuvz: number = qx * uvy - qy * uvx;
|
|
624
|
+
|
|
625
|
+
const w2: number = qw * 2;
|
|
626
|
+
uvx *= w2;
|
|
627
|
+
uvy *= w2;
|
|
628
|
+
uvz *= w2;
|
|
629
|
+
|
|
630
|
+
uuvx *= 2;
|
|
631
|
+
uuvy *= 2;
|
|
632
|
+
uuvz *= 2;
|
|
633
|
+
|
|
634
|
+
out[0] = x + uvx + uuvx;
|
|
635
|
+
out[1] = y + uvy + uuvy;
|
|
636
|
+
out[2] = z + uvz + uuvz;
|
|
637
|
+
return out;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** The unit three-dimensional vector that represents the X-axis. */
|
|
641
|
+
const xAxis: Vector3Like = new Float32Array([1, 0, 0]) as Vector3Like;
|
|
642
|
+
|
|
643
|
+
/** The unit three-dimensional vector that represents the Y-axis. */
|
|
644
|
+
const yAxis: Vector3Like = new Float32Array([0, 1, 0]) as Vector3Like;
|
|
645
|
+
|
|
646
|
+
/** A three-dimensional vector that is used to store intermediary values. */
|
|
647
|
+
const intermediary: Vector3Like = new Float32Array(3) as Vector3Like;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Creates a quaternion that represents the shortest rotation from one vector to another.
|
|
651
|
+
* @param a The first vector.
|
|
652
|
+
* @param b The second vector.
|
|
653
|
+
* @param out The quaternion to store the result in.
|
|
654
|
+
* @returns The quaternion.
|
|
655
|
+
*/
|
|
656
|
+
export function rotationTo<T extends QuaternionLike>(a: Vector3Like, b: Vector3Like, out: T): T {
|
|
657
|
+
const dp: number = dot(a, b);
|
|
658
|
+
|
|
659
|
+
if (dp < epsilon - 1) {
|
|
660
|
+
cross(xAxis, a, intermediary);
|
|
661
|
+
if (getMagnitude(intermediary) < epsilon) { cross(yAxis, a, intermediary); }
|
|
662
|
+
normalize(intermediary, intermediary);
|
|
663
|
+
out[0] = intermediary[0];
|
|
664
|
+
out[1] = intermediary[1];
|
|
665
|
+
out[2] = intermediary[2];
|
|
666
|
+
out[3] = 0;
|
|
667
|
+
return out;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (dp > 1 - epsilon) {
|
|
671
|
+
out[0] = 0;
|
|
672
|
+
out[1] = 0;
|
|
673
|
+
out[2] = 0;
|
|
674
|
+
out[3] = 1;
|
|
675
|
+
return out;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
cross(a, b, intermediary);
|
|
679
|
+
out[0] = intermediary[0];
|
|
680
|
+
out[1] = intermediary[1];
|
|
681
|
+
out[2] = intermediary[2];
|
|
682
|
+
out[3] = 1 + dp;
|
|
683
|
+
return normalizeVector4(out as Vector4Like, out as Vector4Like) as T;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* A quantity with magnitude and direction in three dimensions.
|
|
688
|
+
* @see [Euclidean vector](https://en.wikipedia.org/wiki/Euclidean_vector)
|
|
689
|
+
*/
|
|
690
|
+
export default class Vector3 extends Float32Array implements Vector {
|
|
691
|
+
/**
|
|
692
|
+
* Creates a vector with the given values.
|
|
693
|
+
* @param x The first component.
|
|
694
|
+
* @param y The second component.
|
|
695
|
+
* @param z The third component.
|
|
696
|
+
* @returns A new vector.
|
|
697
|
+
*/
|
|
698
|
+
public static fromValues(x: number, y: number, z: number): Vector3;
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Creates a vector with the given values.
|
|
702
|
+
* @param x The first component.
|
|
703
|
+
* @param y The second component.
|
|
704
|
+
* @param z The third component.
|
|
705
|
+
* @param out The vector to store the result in.
|
|
706
|
+
* @returns A new vector.
|
|
707
|
+
*/
|
|
708
|
+
public static fromValues<T extends Vector3Like>(x: number, y: number, z: number, out: T): T;
|
|
709
|
+
|
|
710
|
+
public static fromValues<T extends Vector3Like>(x: number, y: number, z: number, out: T = new Vector3() as T): T {
|
|
711
|
+
return fromValues(x, y, z, out);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Creates a three-dimensional zero vector.
|
|
716
|
+
* @see [Euclidean vector](https://en.wikipedia.org/wiki/Euclidean_vector)
|
|
717
|
+
*/
|
|
718
|
+
public constructor() {
|
|
719
|
+
super(3);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Determines whether this vector is roughly equivalent to another.
|
|
724
|
+
* @param vector The other vector.
|
|
725
|
+
* @returns Whether the vectors are equivalent.
|
|
726
|
+
*/
|
|
727
|
+
public equals(vector: Vector3Like): boolean {
|
|
728
|
+
return equals(this, vector);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Determines whether this vector is exactly equivalent to another.
|
|
733
|
+
* @param vector The other vector.
|
|
734
|
+
* @returns Whether the vectors are equivalent.
|
|
735
|
+
*/
|
|
736
|
+
public exactEquals(vector: Vector3Like): boolean {
|
|
737
|
+
return exactEquals(this, vector);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Adds two vectors of the same size.
|
|
742
|
+
* @param vector The other vector.
|
|
743
|
+
* @returns The sum of the vectors.
|
|
744
|
+
*/
|
|
745
|
+
public add(vector: Vector3Like): Vector3;
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Adds two vectors of the same size.
|
|
749
|
+
* @param vector The other vector.
|
|
750
|
+
* @param out The vector to store the result in.
|
|
751
|
+
* @returns The sum of the vectors.
|
|
752
|
+
*/
|
|
753
|
+
public add<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
754
|
+
|
|
755
|
+
public add<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
756
|
+
return add(this, vector, out);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Creates a copy of this vector.
|
|
761
|
+
* @returns A copy of this vector.
|
|
762
|
+
*/
|
|
763
|
+
public clone(): Vector3 {
|
|
764
|
+
// TODO: `out` parameter.
|
|
765
|
+
return copy(this, new Vector3());
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Copies the values of another vector into this one.
|
|
770
|
+
* @param vector The vector to copy.
|
|
771
|
+
* @returns This vector.
|
|
772
|
+
*/
|
|
773
|
+
public copy(vector: Vector3Like): this {
|
|
774
|
+
return copy(vector, this);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Multiplies this vector by another.
|
|
779
|
+
* @param vvector The other vector.
|
|
780
|
+
* @returns The product of the vectors.
|
|
781
|
+
*/
|
|
782
|
+
public multiply(vector: Vector3Like): Vector3;
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Multiplies this vector by another.
|
|
786
|
+
* @param vector The other vector.
|
|
787
|
+
* @param out The vector to store the result in.
|
|
788
|
+
* @returns The product of the vectors.
|
|
789
|
+
*/
|
|
790
|
+
public multiply<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
791
|
+
|
|
792
|
+
public multiply<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
793
|
+
return multiply(this, vector, out);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Divides this vector by another.
|
|
798
|
+
* @param vector The other vector.
|
|
799
|
+
* @returns The quotient of the vectors.
|
|
800
|
+
*/
|
|
801
|
+
public divide(vector: Vector3Like): Vector3;
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Divides this vector by another.
|
|
805
|
+
* @param vector The other vector.
|
|
806
|
+
* @param out The vector to store the result in.
|
|
807
|
+
* @returns The quotient of the vectors.
|
|
808
|
+
*/
|
|
809
|
+
public divide<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
810
|
+
|
|
811
|
+
public divide<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
812
|
+
return divide(this, vector, out);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Subtracts another vector from this one.
|
|
817
|
+
* @param vector The other vector.
|
|
818
|
+
* @returns The difference between the vectors.
|
|
819
|
+
*/
|
|
820
|
+
public subtract(vector: Vector3Like): Vector3;
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Subtracts another vector from this one.
|
|
824
|
+
* @param vector The other vector.
|
|
825
|
+
* @param out The vector to store the result in.
|
|
826
|
+
* @returns The difference between the vectors.
|
|
827
|
+
*/
|
|
828
|
+
public subtract<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
829
|
+
|
|
830
|
+
public subtract<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
831
|
+
return subtract(this, vector, out);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Rounds up the components of this vector.
|
|
836
|
+
* @returns The rounded vector.
|
|
837
|
+
*/
|
|
838
|
+
public ceil(): Vector3;
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Rounds up the components of this vector.
|
|
842
|
+
* @param out The vector to store the result in.
|
|
843
|
+
* @returns The rounded vector.
|
|
844
|
+
*/
|
|
845
|
+
public ceil<T extends Vector3Like>(out: T): T;
|
|
846
|
+
|
|
847
|
+
public ceil<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
848
|
+
return ceil(this, out);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Rounds down the components of this vector.
|
|
853
|
+
* @returns The rounded vector.
|
|
854
|
+
*/
|
|
855
|
+
public floor(): Vector3;
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Rounds down the components of this vector.
|
|
859
|
+
* @param out The vector to store the result in.
|
|
860
|
+
* @returns The rounded vector.
|
|
861
|
+
*/
|
|
862
|
+
public floor<T extends Vector3Like>(out: T): T;
|
|
863
|
+
|
|
864
|
+
public floor<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
865
|
+
return floor(this, out);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Rounds the components of this vector.
|
|
870
|
+
* @returns The rounded vector.
|
|
871
|
+
*/
|
|
872
|
+
public round(): Vector3;
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Rounds the components of this vector.
|
|
876
|
+
* @param out The vector to store the result in.
|
|
877
|
+
* @returns The rounded vector.
|
|
878
|
+
*/
|
|
879
|
+
public round<T extends Vector3Like>(out: T): T;
|
|
880
|
+
|
|
881
|
+
public round<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
882
|
+
return round(this, out);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Returns the minimum of this and another vector.
|
|
887
|
+
* @param vector The other vector.
|
|
888
|
+
* @returns The minimum.
|
|
889
|
+
*/
|
|
890
|
+
public min(vector: Vector3Like): Vector3;
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Returns the minimum of this and another vector.
|
|
894
|
+
* @param vector The other vector.
|
|
895
|
+
* @param out The vector to store the result in.
|
|
896
|
+
* @returns The minimum.
|
|
897
|
+
*/
|
|
898
|
+
public min<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
899
|
+
|
|
900
|
+
public min<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
901
|
+
return min(this, vector, out);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* Returns the maximum of this and another vector.
|
|
906
|
+
* @param vector The other vector.
|
|
907
|
+
* @returns The maximum.
|
|
908
|
+
*/
|
|
909
|
+
public max(vector: Vector3Like): Vector3;
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Returns the maximum of this and another vector.
|
|
913
|
+
* @param vector The other vector.
|
|
914
|
+
* @param out The vector to store the result in.
|
|
915
|
+
* @returns The maximum.
|
|
916
|
+
*/
|
|
917
|
+
public max<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
918
|
+
|
|
919
|
+
public max<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
920
|
+
return max(this, vector, out);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Scales this vector by a scalar.
|
|
925
|
+
* @param scalar The scalar.
|
|
926
|
+
* @returns The scaled vector.
|
|
927
|
+
*/
|
|
928
|
+
public scale(scalar: number): Vector3;
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Scales this vector by a scalar.
|
|
932
|
+
* @param scalar The scalar.
|
|
933
|
+
* @param out The vector to store the result in.
|
|
934
|
+
* @returns The scaled vector.
|
|
935
|
+
*/
|
|
936
|
+
public scale<T extends Vector3Like>(scalar: number, out: T): T;
|
|
937
|
+
|
|
938
|
+
public scale<T extends Vector3Like>(scalar: number, out: T = new Vector3() as T): T {
|
|
939
|
+
return scale(this, scalar, out);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Adds another vector to this one after scaling the other by a scalar.
|
|
944
|
+
* @param vector The other vector.
|
|
945
|
+
* @param scalar The scalar.
|
|
946
|
+
* @returns The sum.
|
|
947
|
+
*/
|
|
948
|
+
public scaleAndAdd(vector: Vector3Like, scalar: number): Vector3;
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Adds another vector to this one after scaling the other by a scalar.
|
|
952
|
+
* @param vector The other vector.
|
|
953
|
+
* @param scalar The scalar.
|
|
954
|
+
* @param out The vector to store the result in.
|
|
955
|
+
* @returns The sum.
|
|
956
|
+
*/
|
|
957
|
+
public scaleAndAdd<T extends Vector3Like>(vector: Vector3Like, scalar: number, out: T): T;
|
|
958
|
+
|
|
959
|
+
public scaleAndAdd<T extends Vector3Like>(vector: Vector3Like, scalar: number, out: T = new Vector3() as T): T {
|
|
960
|
+
return scaleAndAdd(this, vector, scalar, out);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Calculates the Euclidean distance between this vector and another.
|
|
965
|
+
* @param vector The other vector.
|
|
966
|
+
* @returns The distance.
|
|
967
|
+
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
968
|
+
*/
|
|
969
|
+
public distance(vector: Vector3Like): number {
|
|
970
|
+
return distance(this, vector);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Calculates the squared Euclidean distance between this vector and another.
|
|
975
|
+
* @param vector The other vector.
|
|
976
|
+
* @returns The squared distance.
|
|
977
|
+
* @see [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)
|
|
978
|
+
*/
|
|
979
|
+
public squaredDistance(vector: Vector3Like): number {
|
|
980
|
+
return squaredDistance(this, vector);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/** The magnitude (length) of this vector. */
|
|
984
|
+
public get magnitude(): number {
|
|
985
|
+
return getMagnitude(this);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/** The squared magnitude (length) of this vector. */
|
|
989
|
+
public get squaredMagnitude(): number {
|
|
990
|
+
return getSquaredMagnitude(this);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Negates this vector.
|
|
995
|
+
* @returns The negated vector.
|
|
996
|
+
*/
|
|
997
|
+
public negate(): Vector3;
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Negates this vector.
|
|
1001
|
+
* @param out The vector to store the result in.
|
|
1002
|
+
* @returns The negated vector.
|
|
1003
|
+
*/
|
|
1004
|
+
public negate<T extends Vector3Like>(out: T): T;
|
|
1005
|
+
|
|
1006
|
+
public negate<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
1007
|
+
return negate(this, out);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/**
|
|
1011
|
+
* Calculates the multiplicative inverse of the components of this vector.
|
|
1012
|
+
* @returns The inverted vector.
|
|
1013
|
+
*/
|
|
1014
|
+
public inverse(): Vector3;
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Calculates the multiplicative inverse of the components of this vector.
|
|
1018
|
+
* @param out The vector to store the result in.
|
|
1019
|
+
* @returns The inverted vector.
|
|
1020
|
+
*/
|
|
1021
|
+
public inverse<T extends Vector3Like>(out: T): T;
|
|
1022
|
+
|
|
1023
|
+
public inverse<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
1024
|
+
return inverse(this, out);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* Normalizes this vector.
|
|
1029
|
+
* @returns The normalized vector.
|
|
1030
|
+
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
1031
|
+
*/
|
|
1032
|
+
public normalize(): Vector3;
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Normalizes this vector.
|
|
1036
|
+
* @param out The vector to store the result in.
|
|
1037
|
+
* @returns The normalized vector.
|
|
1038
|
+
* @see [Unit vector](https://en.wikipedia.org/wiki/Unit_vector)
|
|
1039
|
+
*/
|
|
1040
|
+
public normalize<T extends Vector3Like>(out: T): T;
|
|
1041
|
+
|
|
1042
|
+
public normalize<T extends Vector3Like>(out: T = new Vector3() as T): T {
|
|
1043
|
+
return normalize(this, out);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Calculates the dot product of this and another vector.
|
|
1048
|
+
* @param vector The other vector.
|
|
1049
|
+
* @returns The dot product.
|
|
1050
|
+
* @see [Dot product](https://en.wikipedia.org/wiki/Dot_product)
|
|
1051
|
+
*/
|
|
1052
|
+
public dot(vector: Vector3Like): number {
|
|
1053
|
+
return dot(this, vector);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Calculates the cross product of this and another vector.
|
|
1058
|
+
* @param vector The other vector.
|
|
1059
|
+
* @returns The cross product.
|
|
1060
|
+
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
1061
|
+
*/
|
|
1062
|
+
public cross(vector: Vector3Like): Vector3;
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Calculates the cross product of this and another vector.
|
|
1066
|
+
* @param vector The other vector.
|
|
1067
|
+
* @param out The vector to store the result in.
|
|
1068
|
+
* @returns The cross product.
|
|
1069
|
+
* @see [Cross product](https://en.wikipedia.org/wiki/Cross_product)
|
|
1070
|
+
*/
|
|
1071
|
+
public cross<T extends Vector3Like>(vector: Vector3Like, out: T): T;
|
|
1072
|
+
|
|
1073
|
+
public cross<T extends Vector3Like>(vector: Vector3Like, out: T = new Vector3() as T): T {
|
|
1074
|
+
return cross(this, vector, out);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Performs a linear interpolation between this and another vector.
|
|
1079
|
+
* @param vector The other vector.
|
|
1080
|
+
* @param t The interpolation amount (in `[0,1]`).
|
|
1081
|
+
* @returns The interpolated vector.
|
|
1082
|
+
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
1083
|
+
*/
|
|
1084
|
+
public lerp(vector: Vector3Like, t: number): Vector3;
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Performs a linear interpolation between this and another vector.
|
|
1088
|
+
* @param vector The other vector.
|
|
1089
|
+
* @param t The interpolation amount (in `[0,1]`).
|
|
1090
|
+
* @param out The vector to store the result in.
|
|
1091
|
+
* @returns The interpolated vector.
|
|
1092
|
+
* @see [Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)
|
|
1093
|
+
*/
|
|
1094
|
+
public lerp<T extends Vector3Like>(vector: Vector3Like, t: number, out: T): T;
|
|
1095
|
+
|
|
1096
|
+
public lerp<T extends Vector3Like>(vector: Vector3Like, t: number, out: T = new Vector3() as T): T {
|
|
1097
|
+
return lerp(this, vector, t, out);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* Sets this vector to a random value with the given magnitude.
|
|
1102
|
+
* @param magnitude The magnitude.
|
|
1103
|
+
* @returns This vector.
|
|
1104
|
+
*/
|
|
1105
|
+
public random(magnitude = 1): this {
|
|
1106
|
+
return random(magnitude, this);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Transforms this vector by a three-by-three matrix.
|
|
1111
|
+
* @param matrix The matrix.
|
|
1112
|
+
* @returns The transformed vector.
|
|
1113
|
+
*/
|
|
1114
|
+
public transformMatrix3(matrix: Matrix3Like): Vector3;
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* Transforms this vector by a three-by-three matrix.
|
|
1118
|
+
* @param matrix The matrix.
|
|
1119
|
+
* @param out The vector to store the result in.
|
|
1120
|
+
* @returns The transformed vector.
|
|
1121
|
+
*/
|
|
1122
|
+
public transformMatrix3<T extends Vector3Like>(matrix: Matrix3Like, out: T): T;
|
|
1123
|
+
|
|
1124
|
+
public transformMatrix3<T extends Vector3Like>(matrix: Matrix3Like, out: T = new Vector3() as T): T {
|
|
1125
|
+
return transformMatrix3(this, matrix, out);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Transforms this vector by a four-by-four matrix.
|
|
1130
|
+
* @param matrix The matrix.
|
|
1131
|
+
* @returns The transformed vector.
|
|
1132
|
+
*/
|
|
1133
|
+
public transformMatrix4(matrix: Matrix4Like): Vector3;
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Transforms this vector by a four-by-four matrix.
|
|
1137
|
+
* @param matrix The matrix.
|
|
1138
|
+
* @param out The vector to store the result in.
|
|
1139
|
+
* @returns The transformed vector.
|
|
1140
|
+
*/
|
|
1141
|
+
public transformMatrix4<T extends Vector3Like>(matrix: Matrix4Like, out: T): T;
|
|
1142
|
+
|
|
1143
|
+
public transformMatrix4<T extends Vector3Like>(matrix: Matrix4Like, out: T = new Vector3() as T): T {
|
|
1144
|
+
return transformMatrix4(this, matrix, out);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Rotates this vector around the X-axis.
|
|
1149
|
+
* @param origin The origin of the rotation.
|
|
1150
|
+
* @param radians The angle of rotation in radians.
|
|
1151
|
+
* @returns The rotated vector.
|
|
1152
|
+
*/
|
|
1153
|
+
public rotateX(origin: Vector3Like, radians: number): Vector3;
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Rotates this vector around the X-axis.
|
|
1157
|
+
* @param origin The origin of the rotation.
|
|
1158
|
+
* @param radians The angle of rotation in radians.
|
|
1159
|
+
* @param out The vector to store the result in.
|
|
1160
|
+
* @returns The rotated vector.
|
|
1161
|
+
*/
|
|
1162
|
+
public rotateX<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T): T;
|
|
1163
|
+
|
|
1164
|
+
public rotateX<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T = new Vector3() as T): T {
|
|
1165
|
+
return rotateX(this, origin, radians, out);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* Rotates this vector around the Y-axis.
|
|
1170
|
+
* @param origin The origin of the rotation.
|
|
1171
|
+
* @param radians The angle of rotation in radians.
|
|
1172
|
+
* @returns The rotated vector.
|
|
1173
|
+
*/
|
|
1174
|
+
public rotateY(origin: Vector3Like, radians: number): Vector3;
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Rotates this vector around the Y-axis.
|
|
1178
|
+
* @param origin The origin of the rotation.
|
|
1179
|
+
* @param radians The angle of rotation in radians.
|
|
1180
|
+
* @param out The vector to store the result in.
|
|
1181
|
+
* @returns The rotated vector.
|
|
1182
|
+
*/
|
|
1183
|
+
public rotateY<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T): T;
|
|
1184
|
+
|
|
1185
|
+
public rotateY<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T = new Vector3() as T): T {
|
|
1186
|
+
return rotateY(this, origin, radians, out);
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* Rotates this vector around the Z-axis.
|
|
1191
|
+
* @param origin The origin of the rotation.
|
|
1192
|
+
* @param radians The angle of rotation in radians.
|
|
1193
|
+
* @returns The rotated vector.
|
|
1194
|
+
*/
|
|
1195
|
+
public rotateZ(origin: Vector3Like, radians: number): Vector3;
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Rotates this vector around the Z-axis.
|
|
1199
|
+
* @param origin The origin of the rotation.
|
|
1200
|
+
* @param radians The angle of rotation in radians.
|
|
1201
|
+
* @param out The vector to store the result in.
|
|
1202
|
+
* @returns The rotated vector.
|
|
1203
|
+
*/
|
|
1204
|
+
public rotateZ<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T): T;
|
|
1205
|
+
|
|
1206
|
+
public rotateZ<T extends Vector3Like>(origin: Vector3Like, radians: number, out: T = new Vector3() as T): T {
|
|
1207
|
+
return rotateZ(this, origin, radians, out);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* Gets the angle from this vector to another in radians.
|
|
1212
|
+
* @param vector The other vector.
|
|
1213
|
+
* @returns The angular distance from this vector to the other.
|
|
1214
|
+
*/
|
|
1215
|
+
public angle(vector: Vector3Like): number {
|
|
1216
|
+
return angle(this, vector);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Sets this to the zero vector.
|
|
1221
|
+
* @returns This vector.
|
|
1222
|
+
*/
|
|
1223
|
+
public zero(): this {
|
|
1224
|
+
return zero(this);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Performs a Hermite interpolation with two control points between this vector and another.
|
|
1229
|
+
* @param a The first control point.
|
|
1230
|
+
* @param b The second control point.
|
|
1231
|
+
* @param end The other vector.
|
|
1232
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1233
|
+
* @returns The interpolated vector.
|
|
1234
|
+
* @see [Hermite interpolation](https://en.wikipedia.org/wiki/Hermite_interpolation)
|
|
1235
|
+
*/
|
|
1236
|
+
public hermite(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number): Vector3;
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Performs a Hermite interpolation with two control points between this vector and another.
|
|
1240
|
+
* @param a The first control point.
|
|
1241
|
+
* @param b The second control point.
|
|
1242
|
+
* @param end The other vector.
|
|
1243
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1244
|
+
* @param out The vector to store the result in.
|
|
1245
|
+
* @returns The interpolated vector.
|
|
1246
|
+
* @see [Hermite interpolation](https://en.wikipedia.org/wiki/Hermite_interpolation)
|
|
1247
|
+
*/
|
|
1248
|
+
public hermite<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T): T;
|
|
1249
|
+
|
|
1250
|
+
public hermite<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T = new Vector3() as T): T {
|
|
1251
|
+
return hermite(this, a, b, end, t, out);
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Performs a Bézier interpolation with two control points between this vector and another.
|
|
1256
|
+
* @param a The first control point.
|
|
1257
|
+
* @param b The second control point.
|
|
1258
|
+
* @param end The other vector.
|
|
1259
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1260
|
+
* @returns The interpolated vector.
|
|
1261
|
+
* @see [Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
|
1262
|
+
*/
|
|
1263
|
+
public bezier(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number): Vector3;
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Performs a Bézier interpolation with two control points between this vector and another.
|
|
1267
|
+
* @param a The first control point.
|
|
1268
|
+
* @param b The second control point.
|
|
1269
|
+
* @param end The other vector.
|
|
1270
|
+
* @param t The interpolation amount in the range `[0,1]`.
|
|
1271
|
+
* @param out The vector to store the result in.
|
|
1272
|
+
* @returns The interpolated vector.
|
|
1273
|
+
* @see [Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
|
1274
|
+
*/
|
|
1275
|
+
public bezier<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T): T;
|
|
1276
|
+
|
|
1277
|
+
public bezier<T extends Vector3Like>(a: Vector3Like, b: Vector3Like, end: Vector3Like, t: number, out: T = new Vector3() as T): T {
|
|
1278
|
+
return bezier(this, a, b, end, t, out);
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Transforms this vector by a quaternion.
|
|
1283
|
+
* @param quaternion The quaternion.
|
|
1284
|
+
* @returns The transformed vector.
|
|
1285
|
+
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
1286
|
+
*/
|
|
1287
|
+
public transformQuaternion(quaternion: QuaternionLike): Vector3;
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* Transforms this vector by a quaternion.
|
|
1291
|
+
* @param quaternion The quaternion.
|
|
1292
|
+
* @param out The vector to store the result in.
|
|
1293
|
+
* @returns The transformed vector.
|
|
1294
|
+
* @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
|
|
1295
|
+
*/
|
|
1296
|
+
public transformQuaternion<T extends Vector3Like>(quaternion: QuaternionLike, out: T): T;
|
|
1297
|
+
|
|
1298
|
+
public transformQuaternion<T extends Vector3Like>(quaternion: QuaternionLike, out: T = new Vector3() as T): T {
|
|
1299
|
+
return transformQuaternion(this, quaternion, out);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* Creates a quaternion that represents the shortest rotation from this vector to another.
|
|
1304
|
+
* @param vector The other vector.
|
|
1305
|
+
* @returns The rotation.
|
|
1306
|
+
*/
|
|
1307
|
+
public rotationTo(vector: Vector3Like): Quaternion;
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* Creates a quaternion that represents the shortest rotation from this vector to another.
|
|
1311
|
+
* @param vector The other vector.
|
|
1312
|
+
* @param out The quaternion to store the result in.
|
|
1313
|
+
* @returns The quaternion.
|
|
1314
|
+
*/
|
|
1315
|
+
public rotationTo<T extends QuaternionLike>(vector: Vector3Like, out: T): T;
|
|
1316
|
+
|
|
1317
|
+
public rotationTo<T extends QuaternionLike>(vector: Vector3Like, out: T = new Quaternion() as T): T {
|
|
1318
|
+
return rotationTo(this, vector, out);
|
|
1319
|
+
}
|
|
1320
|
+
}
|