Vector2 and Vector4 — Aspose.3D for TypeScript
Overview
This page covers Vector2 and Vector4 — the two-component and four-component vector types in Aspose.3D for TypeScript. Together with Vector3 and FVector2/FVector3/FVector4, they form the math-primitive set used throughout the API for geometry, animation, and vertex data.
Package: @aspose/3d
Classes
| Class | Description |
|---|---|
Vector2 | Two-component double-precision vector. Used primarily to store UV texture coordinates (u, v). Supports component-wise arithmetic and dot product. |
Vector4 | Four-component double-precision vector. Used for homogeneous coordinates, normals with a W component (e.g., in VertexElementNormal), and RGBA colour data. Components: x, y, z, w. |
FVector2 | Two-component single-precision (float32) variant of Vector2. Used in vertex declarations where reduced precision is acceptable. |
FVector4 | Four-component single-precision (float32) variant of Vector4. |
Relationship to Vector3
Most geometry uses Vector3 (x, y, z). Vector4 is used where a homogeneous W component is needed — for example, vertex normals stored in VertexElementNormal include a W component that is unused and set to 0.
Quick Examples
import { Vector2, Vector4 } from "@aspose/3d";
// UV coordinate
const uv = new Vector2(0.5, 0.75);
console.log(uv.x, uv.y); // 0.5 0.75
// Normal stored as Vector4 (w is unused, set to 0)
const normal = new Vector4(0, 1, 0, 0);
console.log(normal.x, normal.y, normal.z); // 0 1 0
// RGBA colour
const colour = new Vector4(1, 0.5, 0, 1); // orange, fully opaque