123456789_123456789_123456789_123456789_123456789_

Class: IRB::Vec

Relationships & Source Files
Inherits: Object
Defined in: lib/irb/easter-egg.rb

Class Attribute Summary

Class Method Summary

Class Attribute Details

.x (readonly)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 10

attr_reader :x, :y, :z

.y (readonly)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 10

attr_reader :x, :y, :z

.z (readonly)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 10

attr_reader :x, :y, :z

Class Method Details

.cross(other)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 20

def cross(other)
  ox, oy, oz = other.x, other.y, other.z
  Vec.new(@y*oz-@z*oy, @z*ox-@x*oz, @x*oy-@y*ox)
end

.dot(other)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 16

def dot(other)
  @x*other.x + @y*other.y + @z*other.z
end

.initialize(x, y, z)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 6

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

.normalize

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 25

def normalize
  r = Math.sqrt(self.dot(self))
  Vec.new(@x / r, @y / r, @z / r)
end

.sub(other)

[ GitHub ]

  
# File 'lib/irb/easter-egg.rb', line 12

def sub(other)
  Vec.new(@x - other.x, @y - other.y, @z - other.z)
end