Vector2, Vector4 — Aspose.3D TypeScript API Reference
Package: @aspose/3d (v24.12.0)
Vector2 and Vector4 are double-precision vector types exported from @aspose/3d/utilities. Vector2 is the standard 2D coordinate type for UV data. Vector4 is the 4-component homogeneous type used for mesh control points and vertex element data arrays.
import { Vector2, Vector4 } from '@aspose/3d';Vector2
A two-component double-precision vector with x and y fields.
export class Vector2Constructor
new Vector2(x: number = 0.0, y: number = 0.0)Properties
| Property | Type | Access | Description |
|---|---|---|---|
x | number | read/write | First (horizontal) component. |
y | number | read/write | Second (vertical) component. |
length | number | read | Euclidean length: sqrt(x² + y²). |
length2 | number | read | Squared length: x² + y². Cheaper than length when comparing distances. |
Methods
set(x, y)
Set both components in place.
set(newX: number, newY: number): voidgetItem(key) / setItem(key, value)
Index-based access; key must be 0 or 1.
equals(other)
Component-wise equality comparison.
equals(other: Vector2): booleanVector2.parse(input) (static)
Parse a space-separated string "x y" into a Vector2.
static parse(input: string): Vector2toString()
Returns "Vector2(x, y)".
Examples
import { Vector2 } from '@aspose/3d';
const uv = new Vector2(0.5, 0.25);
console.log(uv.x, uv.y); // 0.5 0.25
console.log(uv.length); // ~0.559
const uv2 = Vector2.parse('0.0 1.0');
console.log(uv2.equals(new Vector2(0.0, 1.0))); // true
uv.set(1.0, 0.0);
console.log(uv.toString()); // Vector2(1, 0)
Vector4
A four-component double-precision vector with x, y, z, and w fields. Used as the element type of Mesh.controlPoints and vertex element data arrays.
export class Vector4Constructors
new Vector4()
new Vector4(x: number, y: number, z: number, w: number)
new Vector4(vec3: FVector3, w: number)
new Vector4(vec: FVector2, w: number)The default constructor produces (0, 0, 0, 1). When constructing from FVector3, the xyz components are taken from the vector and w is supplied as the second argument.
Properties
| Property | Type | Access | Description |
|---|---|---|---|
x | number | read/write | First component. |
y | number | read/write | Second component. |
z | number | read/write | Third component. |
w | number | read/write | Fourth (homogeneous) component. For position data, w is 1.0. |
Methods
set(x, y, z, w?)
Set all components in place. w defaults to 1.0.
set(newX: number, newY: number, newZ: number, newW: number = 1.0): voidgetItem(key) / setItem(key, value)
Index-based access; key must be 0–3.
equals(other)
Component-wise equality.
toString()
Returns "Vector4(x, y, z, w)".
Examples
import { Vector4 } from '@aspose/3d';
// Used as mesh control points
const v = new Vector4(1.0, 0.0, 0.0, 1.0);
console.log(v.w); // 1.0
// Index access
console.log(v.getItem(0)); // 1.0
v.setItem(1, 2.0);
console.log(v.y); // 2.0
Populate mesh control points:
import { Scene, Mesh, Vector4 } from '@aspose/3d';
const mesh = new Mesh();
mesh.controlPoints.push(new Vector4(0.0, 0.0, 0.0, 1.0));
mesh.controlPoints.push(new Vector4(1.0, 0.0, 0.0, 1.0));
mesh.controlPoints.push(new Vector4(0.5, 1.0, 0.0, 1.0));
mesh.createPolygon(0, 1, 2);
const scene = new Scene();
scene.rootNode.createChildNode('triangle', mesh);
scene.save('triangle.glb');