A 2D vector with double precision coordinates.
Represents a point or direction in 2D space with x and y components. Provides common vector operations including arithmetic, dot product, magnitude calculation, and normalization.
Value parameters
- x
-
the x-coordinate component
- y
-
the y-coordinate component
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Multiplies the vector by a scalar value.
Multiplies the vector by a scalar value.
Value parameters
- scalar
-
the scalar value to multiply by
Attributes
- Returns
-
a new vector with both components scaled
Adds two vectors component-wise.
Adds two vectors component-wise.
Value parameters
- other
-
the vector to add
Attributes
- Returns
-
a new vector with the sum of corresponding components
Subtracts two vectors component-wise.
Subtracts two vectors component-wise.
Value parameters
- other
-
the vector to subtract
Attributes
- Returns
-
a new vector with the difference of corresponding components
Divides the vector by a scalar value.
Divides the vector by a scalar value.
Value parameters
- scalar
-
the scalar value to divide by (should not be zero)
Attributes
- Returns
-
a new vector with both components divided by the scalar
Generates a random vector within a square area around this vector.
Generates a random vector within a square area around this vector.
Creates a new vector where each component is randomly chosen within the range [this.component - radius, this.component + radius].
Value parameters
- radius
-
the maximum distance from this vector's components
Attributes
- Returns
-
a new random vector within the specified area
Computes the dot product of this vector with another vector.
Computes the dot product of this vector with another vector.
The dot product is useful for determining the angle between vectors and for projection calculations.
Value parameters
- other
-
the other vector
Attributes
- Returns
-
the dot product as a scalar value
Calculates the magnitude (length) of this vector.
Calculates the magnitude (length) of this vector.
Uses the Euclidean distance formula: √(x² + y²)
Attributes
- Returns
-
the magnitude as a non-negative double
Returns a normalized version of this vector (unit vector).
Returns a normalized version of this vector (unit vector).
A normalized vector has magnitude 1.0 and points in the same direction. If this vector has zero magnitude, returns the same vector unchanged.
Attributes
- Returns
-
a new vector with magnitude 1.0, or the original vector if magnitude is 0
Inherited methods
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product