Vector2D

interface Vector2D<P : Vector2D<P>> : Vector<P>

Bidimensional vector with x and y coordinates.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val asAngle: Double

Computes the angle with atan2(y, x).

Link copied to clipboard
abstract val coordinates: DoubleArray

Coordinates for a Cartesian space. Implementors must guarantee that internal state is not exposed.

Link copied to clipboard
abstract val dimensions: Int

The dimensions of the space this vector belongs to.

Link copied to clipboard
open val magnitude: Double

Finds the magnitude of a vector.

Link copied to clipboard
open val x: Double

x coordinate.

Link copied to clipboard
open val y: Double

y coordinate.

Link copied to clipboard
open val zero: P

Origin.

Functions

Link copied to clipboard
open fun angleBetween(other: P): Double

Computes the angle in radians between two vectors.

Link copied to clipboard
open fun coerceAtLeast(minimumMagnitude: Double): P
Link copied to clipboard
open fun coerceAtMost(maximumMagnitude: Double): P
Link copied to clipboard
open fun coerceIn(minimumMagnitude: Double, maximumMagnitude: Double): P

Performs a coercion at least and at most.

Link copied to clipboard
abstract fun distanceTo(other: P): Double

Computes the distance between two vectors, interpreted as points in an Euclidean space. Throws IllegalArgumentException if vectors have different dimensions.

Link copied to clipboard
open operator fun div(other: Double): P

Division by a Double.

Link copied to clipboard
open override fun dot(other: P): Double

Dot product between bidimensional vectors.

Link copied to clipboard
abstract fun fromCoordinates(coordinates: DoubleArray): P

Builds a new Vector from the provided coordinates.

Link copied to clipboard
abstract operator fun get(dim: Int): Double

The coordinate of this vector in the specified dimension relatively to the basis its space is described with.

Link copied to clipboard
open fun isInRectangle(origin: Vector2D<*>, width: Double, height: Double): Boolean

Checks whether the given point is inside a rectangular region described by an origin point and width and height values (only positive).

Link copied to clipboard
abstract operator fun minus(other: P): P

Support for subtraction. Note: the dimensions must coincide.

open operator fun minus(other: Pair<Double, Double>): P

Allows subtraction with a Pair.

Link copied to clipboard
abstract fun newFrom(x: Double, y: Double): P

Creates a new Vector2D with the same type of the current one with different x and y.

Link copied to clipboard
abstract fun normal(): P

Find the normal of a vector.

Link copied to clipboard
open override fun normalized(): P

Normalizes the vector.

Link copied to clipboard
abstract operator fun plus(other: P): P

Support for sum. Note: the dimensions must coincide.

open operator fun plus(other: Pair<Double, Double>): P

Allows summaction with a Pair.

Link copied to clipboard
open fun resized(newLen: Double): P
Link copied to clipboard
open fun surrounding(radius: Double, count: Int = 12): List<P>

Creates a list of count points equally spaced in the circle of given radius with center in this vector.

Link copied to clipboard
open fun surroundingPointAt(versor: P, distance: Double): P

Computes a point which is at a certain distance and angle (expressed as a versor centered in this node) from this one.

open fun surroundingPointAt(angle: Double, distance: Double): P

Computes a point which is at a certain distance and angle (in radians) from this one.

Link copied to clipboard
abstract operator fun times(other: Double): P

Multiplication by a Double.