Vector2 — Aspose.3D FOSS for Java

Overview

Vector2 is a double-precision 2-component vector with x and y components. It is primarily used for UV texture coordinates and 2D calculations.

Package: com.aspose.threed

import com.aspose.threed.*;

Vector2 uv = new Vector2(0.5, 0.75);

Constructor

SignatureDescription
Vector2()Constructs the zero vector (0, 0)
Vector2(double x, double y)Constructs from two components
Vector2(Vector2 other)Copy constructor

Public Fields

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

FieldTypeAccessDescription
xdoublev.xX component
ydoublev.yY component

Computed Properties

NameTypeGetterDescription
lengthdoublegetLength()Euclidean length, read-only
length2doublegetLength2()Squared length, read-only

Methods

MethodReturn TypeDescription
dot(Vector2 rhs)doubleDot product with another Vector2
normalize()Vector2Returns a unit-length copy
set(double x, double y)voidSets both components in place
compareTo(Vector2 other)intLexicographic comparison: returns -1, 0, or 1

Example

import com.aspose.threed.*;

Vector2 a = new Vector2(1.0, 0.0);
Vector2 b = new Vector2(0.0, 1.0);

double dot = a.dot(b);           // 0.0
Vector2 norm = a.normalize();     // Vector2(1.0, 0.0)
System.out.println(a.getLength());  // 1.0

See Also