Vector3

بسته: @aspose/3d (v24.12.0)

Vector3 نوع ریاضی اصلی است که در سراسر @aspose/3d API برای موقعیت‌ها، جهت‌ها، زوایای اویلر و عوامل مقیاس. از @aspose/3d/utilities مسیر فرعی.

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

نقطه میانی بین دو موقعیت را محاسبه کنید و یک بردار جهت را نرمال‌سازی کنید.

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)

بردار را در محل تغییر می‌دهد و هر سه مؤلفه را تنظیم می‌کند.

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

dot(rhs)

حاصل‌ضرب نقطه‌ای اسکالر این بردار و 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)

یک مقدار جدید برمی‌گرداند `Vector3` که حاصل‌ضرب متقاطع این بردار و `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()

یک مقدار جدید را برمی‌گرداند `Vector3` با همان جهت اما طول واحد. برمی‌گرداند `(0, 0, 0)` اگر این بردار طول صفر داشته باشد.

```typescript
normalize(): Vector3

minus(v)

یک مقدار جدید را برمی‌گرداند Vector3 مساوی با this - v.

minus(v: Vector3): Vector3

times(scalar)

یک مقدار جدید را برمی‌گرداند Vector3 مساوی با this * scalar.

times(scalar: number): Vector3

angleBetween(dir, up?)

زاویه را به رادیان بین این بردار و dir. اگر up در صورت ارائه، زاویه در صفحه‌ای که بر … عمود است محاسبه می‌شود up (زاویه‌ی علامت‌دار در آن صفحه).

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

sin()

یک مقدار جدید برمی‌گرداند Vector3 با Math.sin به‌صورت مؤلفه‌به‌مؤلفه اعمال می‌شود.

sin(): Vector3

cos()

یک مقدار جدید برمی‌گرداند Vector3 با Math.cos به‌صورت مؤلفه‌به‌مؤلفه اعمال می‌شود.

cos(): Vector3

equals(other)

ImageRenderOptions true اگر هر سه مؤلفه به‌طور دقیق برابر باشند.

equals(other: Vector3): boolean

compareTo(other)

ImageRenderOptions -1, 0, یا 1 با استفاده از ترتیب لغت‌نامه‌ای بر (x, y, z).

compareTo(other: Vector3): number

static parse(input)

یک رشتهٔ سه عددی که با فاصله جدا شده‌اند را به یک Vector3. اگر قالب نامعتبر باشد، استثنا می‌اندازد.

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

یک رشته به شکل `Vector3(x, y, z)`.

```typescript
toString(): string
 فارسی