Vector3

Pakket: @aspose/3d (v24.12.0)

Vector3 is het primaire wiskundige type dat door de hele @aspose/3d API wordt gebruikt voor posities, richtingen, Euler-hoeken en schaalfactoren. Het wordt geëxporteerd vanuit de @aspose/3d/utilities sub-pad.

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';

ImageRenderOptions

Bereken het middelpunt tussen twee posities en normaliseer een richtingsvector.

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

ImageRenderOptions

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.

ImageRenderOptions

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

ImageRenderOptions

set(x, y, z)

Wijzigt de vector in‑place door alle drie componenten in te stellen.

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

dot(rhs)

Retourneert het scalair product van deze vector en rhs.

dot(rhs: Vector3): number

ImageRenderOptions

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)

Retourneert een nieuwe `Vector3` dat het kruisproduct is van deze vector en `rhs`.

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

ImageRenderOptions

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

Retourneert een nieuwe `Vector3` met dezelfde richting maar een eenheidslengte. Retourneert `(0, 0, 0)` als deze vector een lengte van nul heeft.

```typescript
normalize(): Vector3

minus(v)

Retourneert een nieuwe Vector3 gelijk aan this - v.

minus(v: Vector3): Vector3

times(scalar)

Retourneert een nieuwe Vector3 gelijk aan this * scalar.

times(scalar: number): Vector3

angleBetween(dir, up?)

Retourneert de hoek in radialen tussen deze vector en dir. Als up is opgegeven, wordt de hoek berekend in het vlak loodrecht op up (ondertekende hoek in dat vlak).

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

sin()

Retourneert een nieuwe Vector3 met Math.sin toegepast componentgewijs.

sin(): Vector3

cos()

Retourneert een nieuwe Vector3 met Math.cos toegepast componentgewijs.

cos(): Vector3

equals(other)

ImageRenderOptions true als alle drie componenten strikt gelijk zijn.

equals(other: Vector3): boolean

compareTo(other)

ImageRenderOptions -1, 0, of 1 met lexicografische ordening op (x, y, z).

compareTo(other: Vector3): number

static parse(input)

Parseert een door witruimte gescheiden tekenreeks van drie getallen naar een Vector3. Gooit een uitzondering als het formaat ongeldig is.

static parse(input: string): Vector3

ImageRenderOptions

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


---

### toString()

Retourneert een string in de vorm `Vector3(x, y, z)`.

```typescript
toString(): string
 Nederlands