Vector3

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

Vector3 är den primära matematiska typen som används genom hela @aspose/3d API för positioner, riktningar, Euler-vinklar och skalningsfaktorer. Den exporteras från den @aspose/3d/utilities underkatalogen.

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

Beräkna mittpunkten mellan två positioner och normalisera en riktningsvektor.

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)

Modifierar vektorn på plats och sätter alla tre komponenter.

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

dot(rhs)

Returnerar den skalära skalärprodukten av denna vektor och 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)

Returnerar en ny `Vector3` som är kryssprodukten av denna vektor och `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()

Returnerar en ny `Vector3` med samma riktning men enhetslängd. Returnerar `(0, 0, 0)` om denna vektor har noll längd.

```typescript
normalize(): Vector3

minus(v)

Returnerar en ny Vector3 lika med this - v.

minus(v: Vector3): Vector3

times(scalar)

Returnerar en ny Vector3 lika med this * scalar.

times(scalar: number): Vector3

angleBetween(dir, up?)

Returnerar vinkeln i radianer mellan denna vektor och dir. Om up anges, beräknas vinkeln i planet som är vinkelrätt mot up (signerad vinkel i det planet).

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

sin()

Returnerar en ny Vector3 med Math.sin tillämpas komponentvis.

sin(): Vector3

cos()

Returnerar en ny Vector3 med Math.cos tillämpas komponentvis.

cos(): Vector3

equals(other)

ImageRenderOptions true om alla tre komponenter är strikt lika.

equals(other: Vector3): boolean

compareTo(other)

ImageRenderOptions -1, 0, eller 1 med lexikografisk sortering på (x, y, z).

compareTo(other: Vector3): number

static parse(input)

Analyserar en blankstegsseparerad sträng med tre tal till en Vector3. Kastar ett undantag om formatet är ogiltigt.

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

Returnerar en sträng i formatet `Vector3(x, y, z)`.

```typescript
toString(): string
 Svenska