Vector2D

utils.Vector2D
See theVector2D companion object
case class Vector2D(x: Double, y: Double)

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 Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def *(scalar: Double): Vector2D

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

def +(other: Vector2D): Vector2D

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

def -(other: Vector2D): Vector2D

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

def /(scalar: Double): Vector2D

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

def around(radius: Double): Vector2D

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

def dot(other: Vector2D): Double

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

def magnitude: Double

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

Returns the negation of this vector (unary minus operator).

Returns the negation of this vector (unary minus operator).

Attributes

Returns

a new vector with both components negated

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product