module Geode::VectorGeometry(N)
Overview
Geometric methods for vectors.
Intended to be used as a mix-in on vector types. N is the number of components in the vector.
Direct including types
Defined in:
geode/vectors/geometry.crInstance Method Summary
-
#angle(other : CommonVector(T, N)) : Number forall T
Computes the angle between this vector and another.
-
#dot(other : CommonVector(T, N)) forall T
Computes the dot-product of this vector and another.
-
#dot!(other : CommonVector(T, N)) forall T
Computes the dot-product of this vector and another.
-
#forward(surface : CommonVector(T, N)) : CommonVector forall T
Orients a vector to point in the same direction as another.
-
#length
Computes the magnitude (length) of this vector.
-
#mag
Computes the magnitude (length) of this vector.
-
#mag2
Computes the magnitude (length) squared of this vector.
-
#normalize : CommonVector
Returns a unit vector.
-
#project(other : CommonVector(T, N)) : CommonVector forall T
Computes the projection of this vector onto another vector.
-
#reflect(surface : CommonVector(T, N)) : CommonVector forall T
Computes a reflected vector on a surface.
-
#refract(surface : CommonVector(T, N), eta : Number) : CommonVector forall T
Computes a refracted vector through a surface.
-
#scale_to(length : Number) : CommonVector
Returns a vector with the magnitude specified.
Instance Method Detail
Computes the angle between this vector and another.
Returns the value as radians. The value will be between 0 and pi.
The smallest angle between the vectors is calculated.
Vector[1, 1].angle(Vector[-1, 0]) # => 2.35619449
Vector[1, 1].angle(Vector[1, -1]) # => 1.570796327
Computes the dot-product of this vector and another.
Vector[2, 5, 7].dot(Vector[1, 0, -5]) # => -33
Computes the dot-product of this vector and another.
Values will wrap instead of overflowing and raising an error.
Vector[2, 5, 7].dot!(Vector[1, 0, -5]) # => -33
Orients a vector to point in the same direction as another.
The surface is a vector to orient with.
Computes the magnitude (length) squared of this vector.
This method does not perform a square-root operation,
making it faster than #mag
if the square-root isn't needed.
Vector[3, 4].mag2 # => 25
Returns a unit vector.
Scales the components of the vector equally so that the magnitude (length) is one.
Vector[1, 0, -1].normalize.mag # => 1.0
Computes the projection of this vector onto another vector.
Vector[3, 4].project(Vector[1, 0]) # => (3, 0)
Computes a reflected vector on a surface.
The surface is a normal vector for the surface to reflect against.
Vector[-1, 1].reflect(Vector[0, 1]) # => (1, 1)
Computes a refracted vector through a surface.
The surface is a normal vector for the surface to travel through. eta is the ratio of refractive indices. Returns a zero vector for total internal reflection.
Vector[-1, 1].refract(Vector[0, 1], 1.333) # => (-1.333, -1.0)
Returns a vector with the magnitude specified.
Scales the components of the vector equally.
Vector[1, 0, -1].scale_to(2).mag # => 2.0