diff --git a/src/main/kotlin/math/Vector.kt b/src/main/kotlin/math/Vector.kt index 8bc2a96..dccb03a 100644 --- a/src/main/kotlin/math/Vector.kt +++ b/src/main/kotlin/math/Vector.kt @@ -4,7 +4,7 @@ import kotlin.math.sqrt data class Vector(val x: Float, val y: Float, val z: Float) { val length: Float get() = sqrt(squaredLength) - val squaredLength: Float get() = x * x + y * y + z * z + val squaredLength: Float get() = this dot this fun normalized(): Vector = this / length @@ -14,6 +14,12 @@ data class Vector(val x: Float, val y: Float, val z: Float) { operator fun minus(rhs: Vector): Vector = Vector(x - rhs.x, y - rhs.y, z - rhs.z) operator fun div(rhs: Float): Vector = Vector(x / rhs, y / rhs, z / rhs) + operator fun times(rhs: Vector): Vector = Vector( + y * rhs.z - z * rhs.y, + z * rhs.x - x * rhs.z, + x * rhs.y - y * rhs.x + ) + infix fun dot(rhs: Vector): Float = x * rhs.x + y * rhs.y + z * rhs.z }