Vector2 — Aspose.3D FOSS for Python API Reference
Overview
Vector2 is a double-precision 2-component vector with x and y components. It is primarily used to store UV texture coordinates in VertexElementUV layers and as the tangent type for KeyFrame.next_in_tangent and KeyFrame.out_tangent in animation curves.
Package: aspose.threed.utilities
from aspose.threed.utilities import Vector2Constructor
| Signature | Description |
|---|---|
Vector2() | Constructs (0.0, 0.0) |
Vector2(x, y) | Constructs from two float values |
Properties
| Name | Type | Description |
|---|---|---|
x | float | X component (U in texture coordinates) |
y | float | Y component (V in texture coordinates) |
length | float | Euclidean length (sqrt(x²+y²)), read-only |
length2 | float | Squared length (x²+y²), read-only |
Methods
| Method | Return Type | Description |
|---|---|---|
set(x, y) | None | Sets both components in place |
Vector2.parse(s) | Vector2 | Static. Parses "x y" string representation |
Index Access
Components can be accessed by integer index: v[0] → x, v[1] → y.
Example
from aspose.threed.utilities import Vector2
# Create UV coordinates
uv_bottom_left = Vector2(0.0, 0.0)
uv_bottom_right = Vector2(1.0, 0.0)
uv_top_right = Vector2(1.0, 1.0)
# Length
print(uv_bottom_right.length) # 1.0
# Modify in place
uv_bottom_left.set(0.1, 0.1)
# or via property
uv_bottom_left.x = 0.05
# Use in a VertexElementUV data array
from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
from aspose.threed.entities import VertexElementType
scene = Scene()
mesh = Mesh()
mesh.control_points.append(Vector4(0, 0, 0, 1))
mesh.control_points.append(Vector4(1, 0, 0, 1))
mesh.control_points.append(Vector4(0.5, 1, 0, 1))
mesh.create_polygon(0, 1, 2)
uv_layer = mesh.create_element_uv(VertexElementType.UV)
uv_layer.data.append(Vector2(0.0, 0.0))
uv_layer.data.append(Vector2(1.0, 0.0))
uv_layer.data.append(Vector2(0.5, 1.0))