Vector3 — Aspose.3D FOSS for Python API Reference

Overview

Vector3 is a double-precision 3-component vector with x, y, and z components. It is used throughout Aspose.3D for positions, directions, normals, and scale values. All arithmetic operations return new Vector3 instances; the original is not mutated.

from aspose.threed.utilities import Vector3

# Construct from components
v = Vector3(1.0, 2.0, 3.0)

# Copy constructor
v2 = Vector3(v)

# Default (zero vector)
zero = Vector3()

Constructor

SignatureDescription
Vector3()Constructs the zero vector (0, 0, 0)
Vector3(x, y, z)Constructs from three float components
Vector3(other)Copy constructor — accepts another Vector3

Properties

All components are readable and writable properties; access them without parentheses.

NameTypeDescription
xfloatX component
yfloatY component
zfloatZ component
lengthfloatEuclidean length (sqrt(x²+y²+z²)), read-only
length2floatSquared length (x²+y²+z²), read-only; cheaper than length when only comparison is needed
zeroVector3Returns Vector3(0, 0, 0)
oneVector3Returns Vector3(1, 1, 1)
unit_xVector3Returns Vector3(1, 0, 0)
unit_yVector3Returns Vector3(0, 1, 0)
unit_zVector3Returns Vector3(0, 0, 1)

Methods

MethodReturn TypeDescription
set(x, y, z)NoneSets all three components in place
dot(rhs)floatDot product with another Vector3
cross(rhs)Vector3Cross product — returns a vector perpendicular to both operands
normalize()Vector3Returns a unit-length copy; returns zero vector if length is zero
angle_between(dir)floatAngle in radians between this vector and dir
angle_between(dir, up)floatSigned angle in radians projected onto the plane defined by up
sin()Vector3Component-wise sine
cos()Vector3Component-wise cosine
compare_to(other)intLexicographic comparison: returns −1, 0, or 1
Vector3.parse(s)Vector3Static. Parses "x y z" string representation

Index Access

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

Example

from aspose.threed.utilities import Vector3

# Basic arithmetic (standard Python operators are supported)
a = Vector3(1.0, 0.0, 0.0)
b = Vector3(0.0, 1.0, 0.0)

# Dot and cross products
dot = a.dot(b)           # 0.0
perp = a.cross(b)        # Vector3(0, 0, 1)

# Normalize
direction = Vector3(3.0, 4.0, 0.0)
unit = direction.normalize()   # Vector3(0.6, 0.8, 0.0)
print(unit.length)             # 1.0

# Angle between vectors
import math
angle = a.angle_between(b)
print(math.degrees(angle))    # 90.0

# Use with a scene node transform
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("box")
node.transform.translation = Vector3(10.0, 0.0, 0.0)

See Also