Class Vector3
แพคเกจ: @aspose/3d (v24.12.0)
Vector3 เป็นประเภทคณิตศาสตร์หลักที่ใช้ทั่วทั้ง @aspose/3d API สำหรับตำแหน่ง, ทิศทาง, มุมออยเลอร์, และปัจจัยสเกล มันถูกส่งออกจาก @aspose/3d/utilities เส้นทางย่อย.
export class Vector3import { 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
| Properties | Properties |
|---|---|
new Vector3(x, y, z) | สร้างจากส่วนประกอบเชิงตัวเลขสามส่วน. |
new Vector3(v) | เติมส่วนประกอบทั้งสามด้วยค่าสเกลาร์เดียวกัน. |
Properties
| Properties | Properties | Properties |
|---|---|---|
x | number | ส่วนประกอบ X. สามารถอ่านและเขียนได้. |
y | number | ส่วนประกอบ Y. สามารถอ่านและเขียนได้. |
z | number | ส่วนประกอบ Z. สามารถอ่านและเขียนได้. |
length | number (อ่านอย่างเดียว) | ความยาวยูคลิด: sqrt(x² + y² + z²). |
length2 | number (อ่านอย่างเดียว) | ความยาวกำลังสอง: x² + y² + z². ถูกกว่าที่ length เมื่อเปรียบเทียบเพียงขนาดเท่านั้น. |
zero | Vector3 (อ่านอย่างเดียว) | คืนค่าใหม่ Vector3(0, 0, 0). |
one | Vector3 (อ่านอย่างเดียว) | คืนค่าใหม่ Vector3(1, 1, 1). |
unitX | Vector3 (อ่านอย่างเดียว) | คืนค่าใหม่ Vector3(1, 0, 0). |
unitY | Vector3 (อ่านอย่างเดียว) | คืนค่าใหม่ Vector3(0, 1, 0). |
unitZ | Vector3 (อ่านอย่างเดียว) | คืนค่าใหม่ Vector3(0, 0, 1). |
Properties
set(x, y, z)
เปลี่ยนแปลงค่าเวกเตอร์ในที่เดิมโดยตั้งค่าทั้งสามส่วนประกอบ.
set(newX: number, newY: number, newZ: number): voiddot(rhs)
คืนค่าผลคูณจุดเชิงสเกลาร์ของเวกเตอร์นี้และ rhs.
dot(rhs: Vector3): numberProperties
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): Vector3Properties
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(): Vector3minus(v)
คืนค่าใหม่ Vector3 เท่ากับ this - v.
minus(v: Vector3): Vector3times(scalar)
คืนค่าใหม่ Vector3 เท่ากับ this * scalar.
times(scalar: number): Vector3angleBetween(dir, up?)
คืนค่ามุมเป็นเรเดียนระหว่างเวกเตอร์นี้และ dir. หาก up ถ้าถูกระบุ, มุมจะคำนวณในระนาบที่ตั้งฉากกับ up (มุมที่มีเครื่องหมายในระนาบนั้น).
angleBetween(dir: Vector3, up?: Vector3): numbersin()
ส่งคืนค่าใหม่ Vector3 พร้อมกับ Math.sin ประยุกต์ใช้ต่อส่วนประกอบ.
sin(): Vector3cos()
ส่งคืนค่าใหม่ Vector3 พร้อมกับ Math.cos ประยุกต์ใช้ต่อส่วนประกอบ.
cos(): Vector3equals(other)
Properties true หากส่วนประกอบทั้งสามเท่ากันอย่างเคร่งครัด.
equals(other: Vector3): booleancompareTo(other)
Properties -1, 0, หรือ 1 โดยใช้การเรียงลำดับตามพจนานุกรมบน (x, y, z).
compareTo(other: Vector3): numberstatic parse(input)
แยกวิเคราะห์สตริงที่คั่นด้วยช่องว่างของตัวเลขสามตัวเป็น Vector3. จะโยนข้อยกเว้นหากรูปแบบไม่ถูกต้อง.
static parse(input: string): Vector3Properties
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