struct

Geode::Vector3(T)

Inherits Geode::VectorBase < Geode::CommonVector < Geode::VectorOperations < Geode::VectorMatrices < Geode::VectorGeometry < Geode::VectorComparison < Indexable < Enumerable < Iterable < Struct < Value < Object

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

T is the scalar type.

Constructors

new(x : T, y : T, z : T)

Creates a vector from its components.

Source
new(components : Tuple(T, T, T))

Creates a vector from its components.

Source
new(array : StaticArray(T, 3))

Constructs the vector with pre-existing values.

Source
new(other : CommonVector(T, 3))

Copies the contents of another vector.

Source
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)
Source

Class methods

[](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)
Source
[](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)
Source

Instance methods

alpha

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
Source
beta

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
Source
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)
Source
gamma

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
Source
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.

Source
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)
Source
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)
Source
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)
Source
to_column

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]]
Source
to_row

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]]
Source
tuple

Retrieves the components as a tuple.

Source
x

Retrieves the x component.

Source
y

Retrieves the y component.

Source
z

Retrieves the z component.

Source