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

Properties

คำนวณจุดกึ่งกลางระหว่างตำแหน่งสองตำแหน่งและทำให้เวกเตอร์ทิศทางเป็นมาตรฐาน.

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

Properties

PropertiesProperties
new Vector3(x, y, z)สร้างจากส่วนประกอบเชิงตัวเลขสามส่วน.
new Vector3(v)เติมส่วนประกอบทั้งสามด้วยค่าสเกลาร์เดียวกัน.

Properties

PropertiesPropertiesProperties
xnumberส่วนประกอบ X. สามารถอ่านและเขียนได้.
ynumberส่วนประกอบ Y. สามารถอ่านและเขียนได้.
znumberส่วนประกอบ Z. สามารถอ่านและเขียนได้.
lengthnumber (อ่านอย่างเดียว)ความยาวยูคลิด: sqrt(x² + y² + z²).
length2number (อ่านอย่างเดียว)ความยาวกำลังสอง: x² + y² + z². ถูกกว่าที่ length เมื่อเปรียบเทียบเพียงขนาดเท่านั้น.
zeroVector3 (อ่านอย่างเดียว)คืนค่าใหม่ Vector3(0, 0, 0).
oneVector3 (อ่านอย่างเดียว)คืนค่าใหม่ Vector3(1, 1, 1).
unitXVector3 (อ่านอย่างเดียว)คืนค่าใหม่ Vector3(1, 0, 0).
unitYVector3 (อ่านอย่างเดียว)คืนค่าใหม่ Vector3(0, 1, 0).
unitZVector3 (อ่านอย่างเดียว)คืนค่าใหม่ Vector3(0, 0, 1).

Properties

set(x, y, z)

เปลี่ยนแปลงค่าเวกเตอร์ในที่เดิมโดยตั้งค่าทั้งสามส่วนประกอบ.

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

dot(rhs)

คืนค่าผลคูณจุดเชิงสเกลาร์ของเวกเตอร์นี้และ rhs.

dot(rhs: Vector3): number

Properties

import { Vector3 } from '@aspose/3d/utilities';

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.

cross(rhs: Vector3): Vector3

Properties

import { Vector3 } from '@aspose/3d/utilities';

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) หากเวกเตอร์นี้มีความยาวเป็นศูนย์.

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)

Properties true หากส่วนประกอบทั้งสามเท่ากันอย่างเคร่งครัด.

equals(other: Vector3): boolean

compareTo(other)

Properties -1, 0, หรือ 1 โดยใช้การเรียงลำดับตามพจนานุกรมบน (x, y, z).

compareTo(other: Vector3): number

static parse(input)

แยกวิเคราะห์สตริงที่คั่นด้วยช่องว่างของตัวเลขสามตัวเป็น Vector3. จะโยนข้อยกเว้นหากรูปแบบไม่ถูกต้อง.

static parse(input: string): Vector3

Properties

import { Vector3 } from '@aspose/3d/utilities';

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

toString()

ส่งคืนสตริงในรูปแบบ Vector3(x, y, z).

toString(): string
 ภาษาไทย