Vector2

@Serializable
data class Vector2(val x: Double, val y: Double) : LinearType<Vector2> , EuclideanVector<Vector2> (source)

A 2D vector representation in Cartesian coordinates with methods for mathematical operations and conversions. Implements linear algebra functionalities and provides utility methods for creating and manipulating 2D vectors.

Constructors

Link copied to clipboard
constructor(x: Double)
constructor(x: Double, y: Double)

Types

Link copied to clipboard

Represents an axis in 2D space. Each axis is associated with a unit vector defining its direction.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val length: Double

The Euclidean length of the vector.

Link copied to clipboard

normalized vector

Link copied to clipboard
open override val squaredLength: Double

The squared Euclidean length of the vector.

Link copied to clipboard
val x: Double

The x-coordinate of the vector.

Link copied to clipboard
val xx: Vector2
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val y: Double

The y-coordinate of the vector.

Link copied to clipboard
val yx: Vector2
Link copied to clipboard
val yy: Vector2
Link copied to clipboard
open override val zero: Vector2

returns the zero vector

Functions

Link copied to clipboard
open override fun areaBetween(other: Vector2): Double

returns the area of the parallelogram formed by extruding this over other

Link copied to clipboard
open fun atan2(other: Vector2): Double

atan2 style angle between this and other

Link copied to clipboard

Returns Vector2 whose value is limited between min and max per vector component.

Link copied to clipboard
infix fun cross(right: Vector2): Double

Calculates a cross product between this Vector2 and right.

Link copied to clipboard
open override fun distanceTo(other: Vector2): Double

Calculates the Euclidean distance to other.

Link copied to clipboard
open operator override fun div(scale: Double): Vector2

Divides the current object by the given scale factor.

operator fun div(d: Vector2): Vector2
Link copied to clipboard
open infix override fun dot(right: Vector2): Double

Calculates a dot product between this Vector2 and right.

Link copied to clipboard
operator fun get(i: Int): Double
Link copied to clipboard
open override fun map(function: (Double) -> Double): Vector2

Applies a given function to each component of the vector and returns a new vector with the transformed components.

Link copied to clipboard
fun Vector2.map(beforeLeft: Vector2, beforeRight: Vector2, afterLeft: Vector2, afterRight: Vector2, clamp: Boolean = false): Vector2
Link copied to clipboard
operator fun minus(d: Double): Vector2

open operator override fun minus(right: Vector2): Vector2

Subtracts the specified value from the current value.

Link copied to clipboard
fun mix(o: Vector2, mix: Double): Vector2

Interpolates between the current vector and the given vector o by the specified mixing factor.

Link copied to clipboard
Link copied to clipboard
fun perpendicular(polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): Vector2

Calculates a vector perpendicular to the current one.

Link copied to clipboard
operator fun plus(d: Double): Vector2

open operator override fun plus(right: Vector2): Vector2

Adds the given value right to this value and returns the result.

Link copied to clipboard
open infix fun projectedOn(on: Vector2): Vector2

project this vector on on

Link copied to clipboard
infix fun reflect(surfaceNormal: Vector2): Vector2
Link copied to clipboard
open infix fun reflectedOver(surfaceNormal: Vector2): Vector2

reflect this vector over surfaceNormal

Link copied to clipboard
fun rotate(degrees: Double, origin: Vector2 = ZERO): Vector2

Creates a new Vector2 with the given rotation and origin.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun squaredDistanceTo(other: Vector2): Double

Calculates the squared Euclidean distance to other.

Link copied to clipboard
open operator override fun times(scale: Double): Vector2

Multiplies the current instance by the specified scalar value.

operator fun times(v: Vector2): Vector2
Link copied to clipboard
Link copied to clipboard

Casts to IntVector2.

Link copied to clipboard
operator fun unaryMinus(): Vector2
Link copied to clipboard
fun vector3(x: Double = this.x, y: Double = this.y, z: Double = 0.0): Vector3

Upcasts to Vector3.

Link copied to clipboard
fun vector4(x: Double = this.x, y: Double = this.y, z: Double = 0.0, w: Double = 0.0): Vector4

Upcasts to Vector4.