Class: Ra::Shape::Plane

Inherits:
Base
  • Object
show all
Defined in:
lib/ra/shape/plane.rb

Overview

A plane for all x / z where y = 0. A plane surface is defined:

y = 0

A ray ‘x` / `y` / `z` values at `t` use the `origin` and `direction`:

x = origin.x + direction.x * t
y = origin.y + direction.y * t
z = origin.z + direction.z * t

Therefore, a plane has a single intersection at:

t = -origin.y / direction.y

A direction.y < EPISLON indicates the ray does not intersect the plane.

Instance Attribute Summary

Attributes inherited from Base

#material

Instance Method Summary collapse

Methods inherited from Base

#color, #initialize, #intersect, #normal

Constructor Details

This class inherits a constructor from Ra::Shape::Base

Instance Method Details

#l_normalRa::Tuple

Returns:



42
43
44
45
46
47
48
49
# File 'lib/ra/shape/plane.rb', line 42

def l_normal(*)
  Vector[
    0,
    1,
    0,
    Ra::Tuple::VECTOR
  ]
end

#t_intersect(ray:) ⇒ Array<Numeric>

Parameters:

Returns:

  • (Array<Numeric>)


32
33
34
35
36
37
38
39
# File 'lib/ra/shape/plane.rb', line 32

def t_intersect(ray:)
  origin_y = ray.origin_y
  direction_y = ray.direction_y

  return [] if direction_y.abs < EPSILON

  [-origin_y / direction_y]
end

#uv_point(point:) ⇒ Vector

Returns <u = 0.0..1.0, v = 0.0..1.0>.

Parameters:

  • point (Vector)

    <x, y, z, Tuple::POINT>

Returns:

  • (Vector)

    <u = 0.0..1.0, v = 0.0..1.0>



23
24
25
26
27
28
# File 'lib/ra/shape/plane.rb', line 23

def uv_point(point:)
  Vector[
    point[0] % 1, # u = x % 1
    point[2] % 1, # v = y % 2
  ]
end