Vector3 class
A mutable 3-D vector.
The in-place methods (add, addScaled, crossInto, normalize, ...) never allocate; the operators, cross and normalized return new vectors. Equality compares components exactly, and because the value is mutable, a vector must not change while it is a key in a set or map.
Constructors
- Vector3(double x, double y, double z)
- Create a vector from components.
- Vector3.copy(Vector3 other)
- Copy constructor.
- Vector3.fromOffset(Offset o)
- Create from a Dart Offset with z = 0.
- Vector3.fromXY(double x, double y)
- Create from 2-D components with z = 0 (convenience for 2-D migration).
- Vector3.zero()
- The zero vector.
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- length → double
-
Euclidean length.
no setter
- lengthSquared → double
-
Squared length (avoids sqrt).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- x ↔ double
-
X component.
getter/setter pair
- y ↔ double
-
Y component.
getter/setter pair
- z ↔ double
-
Z component.
getter/setter pair
Methods
-
add(
Vector3 other) → void -
Add
otherin-place. -
addScaled(
Vector3 other, double scalar) → void -
this += other * scalar. -
cross(
Vector3 other) → Vector3 - Cross product (returns a new vector).
-
crossInto(
Vector3 other, Vector3 out) → void -
Write
this × otherintooutwithout allocating. Safe whenoutisthisorother. -
distanceTo(
Vector3 other) → double -
Distance to
other. -
distanceToSquared(
Vector3 other) → double -
Distance squared to
other. -
dot(
Vector3 other) → double - Dot product.
-
negate(
) → void - Negate all components.
-
normalize(
) → double - Normalise in-place. Returns the original length; a (near-)zero vector is left unchanged.
-
normalized(
) → Vector3 -
Return a normalised copy without mutating
this. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
scale(
double scalar) → void -
Multiply all components by
scalar. -
setFrom(
Vector3 other) → void -
Set to
other. -
setValues(
double nx, double ny, double nz) → void -
Set to (
nx,ny,nz). -
setZero(
) → void - Set to zero.
-
sub(
Vector3 other) → void -
Subtract
otherin-place. -
subScaled(
Vector3 other, double scalar) → void -
this -= other * scalar. -
toOffset(
) → Offset - Project to an immutable Offset by discarding z (for Canvas APIs).
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator *(
double s) → Vector3 -
A new vector scaled by
s. -
operator +(
Vector3 other) → Vector3 -
A new vector
this + other. -
operator -(
Vector3 other) → Vector3 -
A new vector
this - other. -
operator /(
double s) → Vector3 -
A new vector divided by
s. -
operator ==(
Object other) → bool -
The equality operator.
override
-
operator unary-(
) → Vector3 - A new, negated vector.