Vector4 — Aspose.3D FOSS for Java

Overview

Vector4 is a double-precision 4-component vector. It is the storage type for mesh control points (where w = 1.0 for positions) and for normal data in VertexElementNormal layers (where w is unused).

Package: com.aspose.threed

import com.aspose.threed.*;

Vector4 point = new Vector4(1.0, 2.0, 3.0, 1.0);

Constructor

SignatureDescription
Vector4()Constructs (0, 0, 0, 1)
Vector4(double x, double y, double z, double w)Constructs from four components
Vector4(double x, double y, double z)Constructs with w = 1.0
Vector4(Vector3 v3)Constructs from a Vector3 with w = 1.0
Vector4(Vector4 other)Copy constructor

Public Fields

Vector4 uses public fields for component access (not getter/setter methods):

FieldTypeAccessDescription
xdoublev.xX component
ydoublev.yY component
zdoublev.zZ component
wdoublev.wW component (homogeneous coordinate)

Methods

MethodReturn TypeDescription
set(double x, double y, double z, double w)voidSets all four components
toVector3()Vector3Returns a Vector3(x, y, z) dropping the w component

Example

import com.aspose.threed.*;

Mesh mesh = new Mesh();

// Add control points (w=1.0 for positions)
mesh.getControlPoints().add(new Vector4(0.0, 0.0, 0.0, 1.0));
mesh.getControlPoints().add(new Vector4(1.0, 0.0, 0.0, 1.0));
mesh.getControlPoints().add(new Vector4(0.5, 1.0, 0.0, 1.0));
mesh.createPolygon(0, 1, 2);

// Convert to Vector3
Vector4 v4 = new Vector4(1.0, 2.0, 3.0, 1.0);
Vector3 v3 = v4.toVector3();   // Vector3(1.0, 2.0, 3.0)

// Construct from Vector3
Vector3 pos = new Vector3(5.0, 0.0, 0.0);
Vector4 homogeneous = new Vector4(pos);   // w = 1.0

See Also