Module: Ra::Tuple

Defined in:
lib/ra/tuple.rb

Overview

A Tuple can classify a Vector as a POINT or VECTOR. For example:

point = Vector[x = 1, y = 2, z = 3, w = Ra::Tuple::POINT]
vector = Vector[x = 1, y = 2, z = 3, w = Ra::Tuple::VECTOR]

Constant Summary collapse

POINT =
1
VECTOR =
0

Class Method Summary collapse

Class Method Details

.cross(source, target) ⇒ Vector

Parameters:

  • source (Vector)
  • target (Vector)

Returns:

  • (Vector)


15
16
17
18
19
20
21
22
23
24
# File 'lib/ra/tuple.rb', line 15

def self.cross(source, target)
  cross = Vector[source[0], source[1], source[2]].cross(Vector[target[0], target[1], target[2]])

  Vector[
    cross[0],
    cross[1],
    cross[2],
    Tuple::VECTOR,
  ]
end

.reflect(vector, normal) ⇒ Vector

Parameters:

  • vector (Vector)
  • normal (Vector)

Returns:

  • (Vector)


29
30
31
# File 'lib/ra/tuple.rb', line 29

def self.reflect(vector, normal)
  vector - (normal * 2 * vector.dot(normal))
end