struct Geode::Vector3(T)

Overview

Vector containing three components. Provides a collection of scalars of the same type.

T is the scalar type.

Defined in:

geode/vectors/vector3.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Geode::VectorBase(T, 3)

map(& : T -> U) : CommonVector forall U map, to_slice : Slice(T) to_slice, to_unsafe : Pointer(T) to_unsafe, unsafe_fetch(index : Int) unsafe_fetch

Constructor methods inherited from struct Geode::VectorBase(T, 3)

new(array : StaticArray(T, N))
new(other : CommonVector(T, M)) forall M
new(&)
new
, zero : self zero

Instance methods inherited from module Geode::CommonVector(T, 3)

inspect(io : IO) : Nil inspect, map(& : T -> U) : CommonVector forall U map, map_with_index(offset = 0, & : T, Int32 -> U) : CommonVector(U, N) forall U map_with_index, size size, to_s(io : IO) : Nil to_s, zip_map(other : CommonVector(U, N), & : T, U -> V) : CommonVector(V, N) forall U, V zip_map

Instance methods inherited from module Geode::VectorOperations(3)

&*(scalar : Number) : CommonVector &*, &+(other : CommonVector(T, N)) : CommonVector forall T &+, &-(other : CommonVector(T, N)) : CommonVector forall T &-, *(scalar : Number) : CommonVector *, +(other : CommonVector(T, N)) : CommonVector forall T +, -(other : CommonVector(T, N)) : CommonVector forall T
- : self
-
, /(scalar : Number) : CommonVector /, //(scalar : Number) : CommonVector //, abs : self abs, abs2 : self abs2, ceil : self ceil, clamp(min : CommonVector(T, N), max : CommonVector(T, N)) : CommonVector forall T
clamp(min, max) : CommonVector
clamp(range : Range(CommonVector(T, N), CommonVector(T, N))) : CommonVector forall T
clamp(range : Range) : CommonVector
clamp
, edge(edge : CommonVector(T, N)) : self forall T
edge(edge : T) : self forall T
edge
, floor : self floor, fraction : self fraction, lerp(other : CommonVector(T, N), t : Number) : CommonVector forall T lerp, round(mode : Number::RoundingMode = :ties_even) : self
round(digits : Number, base = 10, *, mode : Number::RoundingMode = :ties_even) : self
round
, scale(vector : CommonVector(T, N)) : CommonVector forall T
scale(amount : Number) : CommonVector
scale
, scale!(vector : CommonVector(T, N)) : CommonVector forall T
scale!(amount : Number) : CommonVector
scale!
, sign : self sign

Instance methods inherited from module Geode::VectorMatrices(T, 3)

&*(matrix : CommonMatrix(U, M, M)) : CommonVector forall U, M &*, *(matrix : CommonMatrix(U, M, M)) : CommonVector forall U, M *, to_column : CommonMatrix to_column, to_row : CommonMatrix to_row

Instance methods inherited from module Geode::VectorGeometry(3)

angle(other : CommonVector(T, N)) : Number forall T angle, dot(other : CommonVector(T, N)) forall T dot, dot!(other : CommonVector(T, N)) forall T dot!, forward(surface : CommonVector(T, N)) : CommonVector forall T forward, length length, mag mag, mag2 mag2, normalize : CommonVector normalize, project(other : CommonVector(T, N)) : CommonVector forall T project, reflect(surface : CommonVector(T, N)) : CommonVector forall T reflect, refract(surface : CommonVector(T, N), eta : Number) : CommonVector forall T refract, scale_to(length : Number) : CommonVector scale_to

Instance methods inherited from module Geode::VectorComparison(3)

==(other : CommonVector(T, N)) forall T ==, compare(other : CommonVector(T, N)) : CommonVector(Int32, N) forall T compare, eq?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T eq?, ge?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T ge?, gt?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T gt?, le?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T le?, lt?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T lt?, near_zero?(tolerance) near_zero?, zero? zero?

Constructor Detail

def self.new(x : T, y : T, z : T) #

Creates a vector from its components.


[View source]
def self.new(components : Tuple(T, T, T)) #

Creates a vector from its components.


[View source]
def self.new(array : StaticArray(T, 3)) #

Constructs the vector with pre-existing values.


[View source]
def self.new(other : CommonVector(T, 3)) #

Copies the contents of another vector.


[View source]
def self.new(&) #

Constructs the vector by yielding for each component.

The value of each component should be returned from the block. The block will be given the index of each component as an argument.

Vector3(Int32).new { |i| i * 5 } # => (0, 5, 10)

[View source]

Class Method Detail

def self.[](x : T, y : T, z : T) #

Constructs a vector with existing components.

The type of the components is derived from the type of each argument.

Vector3[1, 2, 3] # => (1, 2, 3)

[View source]
def self.[](x, y, z) #

Constructs a vector with existing components.

The type of the components is specified by the type parameter. Each value is cast to the type T.

Vector3F[1, 2, 3] # => (1.0, 2.0, 3.0)

[View source]

Instance Method Detail

def alpha : Number #

Computes the angle (directional cosine) of the vector from the x-axis.

The value will be in radians from 0 to pi.

Vector3[1, 2, 3].alpha # => 1.300246563

[View source]
def beta : Number #

Computes the angle (directional cosine) of the vector from the y-axis.

The value will be in radians from 0 to pi.

Vector3[1, 2, 3].beta # => 1.006853685

[View source]
def cross(other : CommonVector(U, 3)) : CommonVector forall U #

Computes the cross-product of this and another vector.

Vector3[1, 3, 4].cross(Vector3[2, -5, 8]) # => (44, 0, -11)

[View source]
def gamma : Number #

Computes the angle (directional cosine) of the vector from the z-axis.

The value will be in radians from 0 to pi.

Vector3[1, 2, 3].gamma # => 0.640522312

[View source]
def rotate(angle : Number | Angle, axis : CommonVector(U, 3)) : CommonVector forall U #

Computes a new vector that is rotated around an arbitrary axis.

The angle bus be a Number in radians or an Angle.

TODO Not implemented.


[View source]
def rotate_x(angle : Number | Angle) : Vector3 #

Computes a new vector that is rotated around the x-axis.

The angle must be a Number in radians or an Angle.

Vector3[1.0, 1.0, 1.0].rotate_x(90.degrees) # => (1.0, -1.0, 1.0)

[View source]
def rotate_y(angle : Number | Angle) : Vector3 #

Computes a new vector that is rotated around the y-axis.

The angle must be a Number in radians or an Angle.

Vector3[1.0, 1.0, 1.0].rotate_y(90.degrees) # => (1.0, 1.0, -1.0)

[View source]
def rotate_z(angle : Number | Angle) : Vector3 #

Computes a new vector that is rotated around the z-axis.

The angle must be a Number in radians or an Angle.

Vector3[1.0, 1.0, 1.0].rotate_z(90.degrees) # => (-1.0, 1.0, 1.0)

[View source]
def to_column : Matrix3x1(T) #

Converts this vector to a column vector, in other words a matrix with one column.

vector = Vector3[1, 2, 3]
vector.to_column # => [[1], [2], [3]]

[View source]
def to_row : Matrix1x3(T) #

Converts this vector to a row vector, in other words a matrix with one row.

vector = Vector3[1, 2, 3]
vector.to_row # => [[1, 2, 3]]

[View source]
def tuple : Tuple(T, T, T) #

Retrieves the components as a tuple.


[View source]
def x : T #

Retrieves the x component.


[View source]
def y : T #

Retrieves the y component.


[View source]
def z : T #

Retrieves the z component.


[View source]