Vector3
Paket: @aspose/3d (v24.12.0)
Vector3 API genelinde kullanılan birincil matematik türüdür @aspose/3d konumlar, yönler, Euler açıları ve ölçek faktörleri için API. Bu, @aspose/3d/utilities alt-yol.
export class Vector3import { Vector3 } from '@aspose/3d/utilities';
// or via the main entry point when used with Transform/GlobalTransform
import { Scene } from '@aspose/3d';Enumerations
İki konum arasındaki orta noktayı hesaplayın ve bir yön vektörünü normallaştırın.
import { Vector3 } from '@aspose/3d/utilities';
const a = new Vector3(1, 0, 0);
const b = new Vector3(0, 0, 4);
// Midpoint: average the components manually
const mid = new Vector3(
(a.x + b.x) * 0.5,
(a.y + b.y) * 0.5,
(a.z + b.z) * 0.5
);
console.log(`Midpoint: ${mid}`);
// Midpoint: Vector3(0.5, 0, 2)
// Normalized direction from a to b
const dir = b.minus(a).normalize();
console.log(`Direction: ${dir}`);
// Direction: Vector3(-0.2425..., 0, 0.9701...)
Enumerations
| Name | Type | Access | Description |
|---|---|---|---|
x | number | Read/Write | Gets the x. |
y | number | Read/Write | Gets the y. |
z | number | Read/Write | Gets the z. |
length | number | Read | Gets the length. |
length2 | number | Read | Gets the length2. |
zero | Vector3 | Read | Gets the zero. |
one | Vector3 | Read | Gets the one. |
unitX | Vector3 | Read | Gets the unit x. |
unitY | Vector3 | Read | Gets the unit y. |
unitZ | Vector3 | Read | Gets the unit z. |
Enumerations
| Signature | Description |
|---|---|
constructor(x: number, y: number, z: number) | Creates a new Vector3 using either a number or FVector3 for x and separate y, z |
constructor(vec: FVector3) | |
constructor(v: number) | |
| `constructor(x: number | FVector3, y: number, z: number)` |
set(newX: number, newY: number, newZ: number) | Assigns new x, y, z values to the vector |
dot(rhs: Vector3) → number | Returns the dot product of this vector with another Vector3 |
cross(rhs: Vector3) → Vector3 | |
normalize() → Vector3 | Returns a unit-length vector in the same direction |
angleBetween(dir: Vector3, up: Vector3) → number | Returns the angle in radians between this vector and dir, using up as reference |
sin() → Vector3 | Returns a vector whose components are the sine of this vector’s components |
cos() → Vector3 | |
compareTo(other: Vector3) → number | Returns a numeric comparison of this vector with another vector |
parse(input: string) → Vector3 | Creates a Vector3 from a string representation |
getItem(key: number) → number | |
setItem(key: number, value: number) | Sets the item value. |
toString() → string | |
equals(other: Vector3) → boolean | Returns true if this vector has the same components as another |
minus(v: Vector3) → Vector3 | Returns a new vector equal to this vector minus the given vector |
times(scalar: number) → Vector3 | Returns a new vector scaled by the given scalar |
Enumerations
set(x, y, z)
Vektörü yerinde değiştirir, üç bileşeni de ayarlar.
set(newX: number, newY: number, newZ: number): voiddot(rhs)
Bu vektör ile … arasındaki skaler nokta çarpımını döndürür rhs.
dot(rhs: Vector3): numberEnumerations
const up = new Vector3(0, 1, 0);
const dir = new Vector3(0.5, 0.5, 0).normalize();
const alignment = up.dot(dir);
console.log(Dot: ${alignment.toFixed(4)}); // Dot: 0.7071
---
### cross(rhs)
Yeni bir nesne döndürür `Vector3` bu vektör ile ... arasındaki çapraz çarpım olan `rhs`.
```typescript
cross(rhs: Vector3): Vector3Enumerations
const right = new Vector3(1, 0, 0);
const up = new Vector3(0, 1, 0);
const forward = right.cross(up);
console.log(Forward: ${forward});
// Forward: Vector3(0, 0, -1)
---
### normalize()
Yeni bir nesne döndürür `Vector3` aynı yönde ancak birim uzunlukta. Döndürür `(0, 0, 0)` eğer bu vektörün uzunluğu sıfırsa.
```typescript
normalize(): Vector3minus(v)
Yeni bir nesne döndürür Vector3 eşittir this - v.
minus(v: Vector3): Vector3times(scalar)
Yeni bir nesne döndürür Vector3 eşittir this * scalar.
times(scalar: number): Vector3angleBetween(dir, up?)
Bu vektör ile arasındaki açıyı radyan cinsinden döndürür dir. Eğer up verildiğinde, açı, ona dik düzlemde hesaplanır up (o düzlemde işaretli açı).
angleBetween(dir: Vector3, up?: Vector3): numbersin()
Yeni bir tane döndürür Vector3 ile Math.sin bileşen bazında uygulanır.
sin(): Vector3cos()
Yeni bir tane döndürür Vector3 ile Math.cos bileşen bazında uygulanır.
cos(): Vector3equals(other)
Enumerations true eğer üç bileşen de kesinlikle eşitse.
equals(other: Vector3): booleancompareTo(other)
Enumerations -1, 0, ya da 1 üzerinde leksikografik sıralama kullanarak (x, y, z).
compareTo(other: Vector3): numberstatic parse(input)
Üç sayıyı boşlukla ayrılmış bir dizeyi bir … içine ayrıştırır Vector3. Biçim geçersizse bir istisna fırlatır.
static parse(input: string): Vector3Enumerations
const v = Vector3.parse(‘1.5 2.0 -3.0’);
console.log(${v}); // Vector3(1.5, 2, -3)
---
### toString()
Şu biçimde bir dize döndürür `Vector3(x, y, z)`.
```typescript
toString(): string