Class Vector3
Class Vector3
包:: @aspose/3d (v24.12.0)
Vector3 是整个 API 中使用的主要数学类型 @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