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
| Signature | Description |
|---|---|
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.
| Name | Type | Description |
|---|---|---|
x | float | X component |
y | float | Y component |
z | float | Z component |
length | float | Euclidean length (sqrt(x²+y²+z²)), read-only |
length2 | float | Squared length (x²+y²+z²), read-only; cheaper than length when only comparison is needed |
zero | Vector3 | Returns Vector3(0, 0, 0) |
one | Vector3 | Returns Vector3(1, 1, 1) |
unit_x | Vector3 | Returns Vector3(1, 0, 0) |
unit_y | Vector3 | Returns Vector3(0, 1, 0) |
unit_z | Vector3 | Returns Vector3(0, 0, 1) |
Methods
| Method | Return Type | Description |
|---|---|---|
set(x, y, z) | None | Sets all three components in place |
dot(rhs) | float | Dot product with another Vector3 |
cross(rhs) | Vector3 | Cross product — returns a vector perpendicular to both operands |
normalize() | Vector3 | Returns a unit-length copy; returns zero vector if length is zero |
angle_between(dir) | float | Angle in radians between this vector and dir |
angle_between(dir, up) | float | Signed angle in radians projected onto the plane defined by up |
sin() | Vector3 | Component-wise sine |
cos() | Vector3 | Component-wise cosine |
compare_to(other) | int | Lexicographic comparison: returns −1, 0, or 1 |
Vector3.parse(s) | Vector3 | Static. 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)