class GravityCenter
Attributes
x1[R]
x2[R]
x3[R]
y1[R]
y2[R]
y3[R]
Public Class Methods
create(*val)
click to toggle source
# File lib/gravity_center.rb, line 8 def self.create(*val) gc = self.new gc.instance_eval do v = [val].flatten @x1 = BigDecimal(v[0].to_s) @y1 = BigDecimal(v[1].to_s) @x2 = BigDecimal(v[2].to_s) @y2 = BigDecimal(v[3].to_s) @x3 = BigDecimal(v[4].to_s) @y3 = BigDecimal(v[5].to_s) end gc end
Public Instance Methods
center()
click to toggle source
# File lib/gravity_center.rb, line 60 def center [center_x, center_y] end
center_sx()
click to toggle source
# File lib/gravity_center.rb, line 42 def center_sx @center_sx ||= calc_center_sx @center_sx end
center_sy()
click to toggle source
# File lib/gravity_center.rb, line 51 def center_sy @center_sy ||= calc_center_sy @center_sy end
center_x()
click to toggle source
# File lib/gravity_center.rb, line 47 def center_x center_sx + x3 end
center_y()
click to toggle source
# File lib/gravity_center.rb, line 56 def center_y center_sy + y3 end
sx1()
click to toggle source
# File lib/gravity_center.rb, line 22 def sx1 @sx1 ||= x1 - x3 @sx1 end
sx2()
click to toggle source
# File lib/gravity_center.rb, line 32 def sx2 @sx2 ||= x2 - x3 @sx2 end
sy1()
click to toggle source
# File lib/gravity_center.rb, line 27 def sy1 @sy1 ||= y1 - y3 @sy1 end
sy2()
click to toggle source
# File lib/gravity_center.rb, line 37 def sy2 @sy2 ||= y2 - y3 @sy2 end
Private Instance Methods
calc_center_sx()
click to toggle source
# File lib/gravity_center.rb, line 66 def calc_center_sx (sx1 + sx2) / 3 end
calc_center_sy()
click to toggle source
# File lib/gravity_center.rb, line 70 def calc_center_sy (sy1 + sy2) / 3 end