Vector
class in package klyn.math.geometry

    public class Vector<NUMBER extends AbstractNumber = Double>:

Vector

Represents a two-dimensional vector.

`Vector` is intended for displacement and direction math. Use `Point` for absolute positions.

Example:

    velocity = Vector<Double>(3.0, 4.0)
    print(velocity.magnitude())

Properties

Modifier and Type | Member | Description
--- | --- | ---
public property | x `x as NUMBER` | Horizontal component.
public propert | y `y y as NUMBER` | Vertical component.

Constructors

Modifier and Type | Member | Description
--- | --- | ---
public | Vector `Vector(x as NUMBER, y as NUMBER):` | Creates a vector from its components.

Methods

Modifier and Type | Member | Description
--- | --- | ---
public | cross `cross(other as Vector<NUMBER>) as Double:` | Computes the two-dimensional cross product determinant.
public | dot `dot(other as Vector<NUMBER>) as Double:` | Computes the dot product with another vector.
public | magnitude `magnitude() as Double:` | Computes the Euclidean vector length.
public | normalize `normalize() as Vector<Double>:` | Returns a unit vector with the same direction.
public override | toString `toString() as String:` | Returns a readable representation of the vector.

Operators

Modifier and Type | Member | Description
--- | --- | ---
public static | operator*(v1 as Vector<NUMBER>, scalar as NUMBER) as Vector<NUMBER>: | Multiplies a vector by a scalar.
public static | operator+(v1 as Vector<NUMBER>, v2 as Vector<NUMBER>) as Vector<NUMBER>: | Adds two vectors component by component.
public static | operator-(v1 as Vector<NUMBER>, v2 as Vector<NUMBER>) as Vector<NUMBER>: | Subtracts two vectors component by component.
public static | operator/(v1 as Vector<NUMBER>, scalar as NUMBER) as Vector<Double>: | Divides a vector by a scalar.