Vector4 — Aspose.3D FOSS for Python API Reference

Overview

Vector4 is a double-precision 4-component vector with x, y, z, and w components. It is the primary type used for control points in Mesh.control_points (where w = 1.0 for Cartesian positions) and for normal data in VertexElementNormal.

Package: aspose.threed.utilities

from aspose.threed.utilities import Vector4

Constructor

SignatureDescription
Vector4()Constructs (0, 0, 0, 1)
Vector4(x, y, z)Constructs from three components; w defaults to 1.0
Vector4(x, y, z, w)Constructs from four explicit components
Vector4(vec3)Constructs from a Vector3; w set to 1.0
Vector4(vec3, w)Constructs from a Vector3 plus explicit w

Properties

NameTypeDescription
xfloatX component
yfloatY component
zfloatZ component
wfloatW component (homogeneous weight; typically 1.0 for positions)

Methods

MethodReturn TypeDescription
set(x, y, z, w=1.0)NoneSets all four components in place

Index Access

Components can be accessed by integer index: v[0] → x, v[1] → y, v[2] → z, v[3] → w.

Example

from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4

scene = Scene()
mesh = Mesh()

# Control points use Vector4 with w=1.0
mesh.control_points.append(Vector4(0.0, 0.0, 0.0, 1.0))
mesh.control_points.append(Vector4(1.0, 0.0, 0.0, 1.0))
mesh.control_points.append(Vector4(0.5, 1.0, 0.0, 1.0))

# Create a triangle polygon
mesh.create_polygon(0, 1, 2)

node = scene.root_node.create_child_node("triangle", mesh)

# Reading a control point
pt = mesh.control_points[0]
print(pt.x, pt.y, pt.z, pt.w)   # 0.0 0.0 0.0 1.0

# Construct from Vector3
from aspose.threed.utilities import Vector3
v3 = Vector3(5.0, 3.0, 2.0)
v4 = Vector4(v3)           # w defaults to 1.0
v4b = Vector4(v3, 0.0)     # explicit w for direction (w=0)

See Also