Vector3

Gói: @aspose/3d (v24.12.0)

Vector3 là kiểu toán học chính được sử dụng xuyên suốt @aspose/3d API cho vị trí, hướng, góc Euler và hệ số tỉ lệ. Nó được xuất ra từ @aspose/3d/utilities đường dẫn phụ.

export class Vector3
import { Vector3 } from '@aspose/3d/utilities';
// or via the main entry point when used with Transform/GlobalTransform
import { Scene } from '@aspose/3d';

Enumerations

Tính điểm trung bình giữa hai vị trí và chuẩn hoá một vector hướng.

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

NameTypeAccessDescription
xnumberRead/WriteGets the x.
ynumberRead/WriteGets the y.
znumberRead/WriteGets the z.
lengthnumberReadGets the length.
length2numberReadGets the length2.
zeroVector3ReadGets the zero.
oneVector3ReadGets the one.
unitXVector3ReadGets the unit x.
unitYVector3ReadGets the unit y.
unitZVector3ReadGets the unit z.

Enumerations

SignatureDescription
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: numberFVector3, y: number, z: number)`
set(newX: number, newY: number, newZ: number)Assigns new x, y, z values to the vector
dot(rhs: Vector3)numberReturns the dot product of this vector with another Vector3
cross(rhs: Vector3)Vector3
normalize()Vector3Returns a unit-length vector in the same direction
angleBetween(dir: Vector3, up: Vector3)numberReturns the angle in radians between this vector and dir, using up as reference
sin()Vector3Returns a vector whose components are the sine of this vector’s components
cos()Vector3
compareTo(other: Vector3)numberReturns a numeric comparison of this vector with another vector
parse(input: string)Vector3Creates a Vector3 from a string representation
getItem(key: number)number
setItem(key: number, value: number)Sets the item value.
toString()string
equals(other: Vector3)booleanReturns true if this vector has the same components as another
minus(v: Vector3)Vector3Returns a new vector equal to this vector minus the given vector
times(scalar: number)Vector3Returns a new vector scaled by the given scalar

Enumerations

set(x, y, z)

Thay đổi vector tại chỗ, thiết lập cả ba thành phần.

set(newX: number, newY: number, newZ: number): void

dot(rhs)

Trả về tích vô hướng của vector này và rhs.

dot(rhs: Vector3): number

Enumerations

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)

Trả về một đối tượng mới `Vector3` là tích có hướng của vector này và `rhs`.

```typescript
cross(rhs: Vector3): Vector3

Enumerations

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()

Trả về một đối tượng mới `Vector3` có cùng hướng nhưng độ dài đơn vị. Trả về `(0, 0, 0)` nếu vector này có độ dài bằng 0.

```typescript
normalize(): Vector3

minus(v)

Trả về một đối tượng mới Vector3 bằng this - v.

minus(v: Vector3): Vector3

times(scalar)

Trả về một đối tượng mới Vector3 bằng this * scalar.

times(scalar: number): Vector3

angleBetween(dir, up?)

Trả về góc tính bằng radian giữa vectơ này và dir. Nếu up được cung cấp, góc được tính trong mặt phẳng vuông góc với up (góc có dấu trong mặt phẳng đó).

angleBetween(dir: Vector3, up?: Vector3): number

sin()

Trả về một đối tượng mới Vector3 với Math.sin được áp dụng từng thành phần.

sin(): Vector3

cos()

Trả về một đối tượng mới Vector3 với Math.cos được áp dụng từng thành phần.

cos(): Vector3

equals(other)

Enumerations true nếu ba thành phần đều hoàn toàn bằng nhau.

equals(other: Vector3): boolean

compareTo(other)

Enumerations -1, 0, hoặc 1 sử dụng thứ tự từ điển trên (x, y, z).

compareTo(other: Vector3): number

static parse(input)

Phân tích một chuỗi ba số cách nhau bằng khoảng trắng thành một Vector3. Ném ngoại lệ nếu định dạng không hợp lệ.

static parse(input: string): Vector3

Enumerations

const v = Vector3.parse(‘1.5 2.0 -3.0’); console.log(${v}); // Vector3(1.5, 2, -3)


---

### toString()

Trả về một chuỗi ở dạng `Vector3(x, y, z)`.

```typescript
toString(): string
 Tiếng Việt