Class: RubyGL::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygl/geometry.rb

Overview

All Point Operations Return New Points

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, z = 0) ⇒ Point

Returns a new instance of Point.



10
11
12
13
14
# File 'lib/rubygl/geometry.rb', line 10

def initialize(x, y, z = 0)
    @x = x
    @y = y
    @z = z
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/rubygl/geometry.rb', line 8

def x
  @x
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/rubygl/geometry.rb', line 8

def y
  @y
end

#zObject

Returns the value of attribute z.



8
9
10
# File 'lib/rubygl/geometry.rb', line 8

def z
  @z
end

Instance Method Details

#*(point) ⇒ Object



24
25
26
# File 'lib/rubygl/geometry.rb', line 24

def *(point)
    Point.new(@x * point.x, @y * point.y, @z * point.z)
end

#+(point) ⇒ Object



16
17
18
# File 'lib/rubygl/geometry.rb', line 16

def +(point)
    Point.new(@x + point.x, @y + point.y, @z + point.z)
end

#-(point) ⇒ Object



20
21
22
# File 'lib/rubygl/geometry.rb', line 20

def -(point)
    Point.new(@x - point.x, @y - point.y, @z - point.z)
end

#distance(point) ⇒ Object



32
33
34
35
36
# File 'lib/rubygl/geometry.rb', line 32

def distance(point)
    temp = self - point
    
    Math::sqrt(temp.x * temp.x + temp.y * temp.y + temp.z * temp.z)
end

#midpoint(point) ⇒ Object



38
39
40
# File 'lib/rubygl/geometry.rb', line 38

def midpoint(point)
    Point.new((@x + point.x) * 0.5, (@y + point.y) * 0.5, (@z + point.z) * 0.5)
end

#scale(value) ⇒ Object



28
29
30
# File 'lib/rubygl/geometry.rb', line 28

def scale(value)
    Point.new(@x * value, @y * value, @z * value)
end

#to_aObject



46
47
48
# File 'lib/rubygl/geometry.rb', line 46

def to_a
    self.to_ary
end

#to_aryObject



42
43
44
# File 'lib/rubygl/geometry.rb', line 42

def to_ary
    [@x, @y, @z]
end