Vector2d
A 2D vector with components in a specified unit system.
This class represents a 2D vector \(\mathbf{v} = (x, y)\) where both components have the same unit type \(U\). Common use cases include position vectors (with distance units), velocity vectors (with velocity units), and acceleration vectors (with acceleration units).
Operations
Vector arithmetic:
Addition: \(\mathbf{v}_1 + \mathbf{v}_2 = (x_1 + x_2, y_1 + y_2)\)
Subtraction: \(\mathbf{v}_1 - \mathbf{v}_2 = (x_1 - x_2, y_1 - y_2)\)
Negation: \(-\mathbf{v} = (-x, -y)\)
Scalar operations:
Multiplication: \(c \cdot \mathbf{v} = (c \cdot x, c \cdot y)\)
Division: \(\mathbf{v} / c = (x / c, y / c)\)
Vector products:
Dot product: \(\mathbf{v}_1 \cdot \mathbf{v}_2 = x_1 x_2 + y_1 y_2\)
Squared norm: \(\|\mathbf{v}\|^2 = x^2 + y^2\)
Norm (magnitude): \(\|\mathbf{v}\| = \sqrt{x^2 + y^2}\)
Example Usage
// Position vector
val position = Vector2d(10.0.inches, 5.0.inches)
// Velocity vector
val velocity = Vector2d(2.0.inchesPerSecond, 3.0.inchesPerSecond)
// Vector operations
val sum = position + Vector2d(1.0.inches, 2.0.inches)
val scaled = position * 2.0
val magnitude = position.norm()Type Parameters
the unit type for both components (e.g., DistanceUnit, VelocityUnit)
Properties
Functions
Returns the angle of this vector as a Rotation2d.
Returns the angle of this vector as a Rotation2d, assuming this vector is already normalized (unit length).
Negates the vector.