class GeoTriangleExt::CircumCenter

Public Class Methods

create(*co) click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 8
def create(*co)
  cc = self.new
  co.take(3).each{|c| cc.coordinates << c}
  cc
end

Public Instance Methods

center() click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 45
def center
  return unless valid_functions?
  @center_point ||= calc_center
  @center_point
end
coordinates() click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 20
def coordinates
  @coordinates ||= []
  @coordinates = @coordinates.uniq
  @coordinates = @coordinates.take(3) if @coordinates.size > 3
  @coordinates
end
functions() click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 33
def functions
  @functions ||= create_functions
  @functions
end
set_coordinate(x, y) click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 16
def set_coordinate(x, y)
  coordinates << [x, y]
end
valid_coordinates?() click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 27
def valid_coordinates?
  return false unless coordinates.size == 3
  return false unless coordinates.all?{|c| c.size == 2}
  true
end
valid_functions?() click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 38
def valid_functions?
  return false if functions.size < 2
  return false if functions.combination(2).any?{|f1, f2|
    f1.orthogonal_slope == f2.orthogonal_slope}
  true
end

Private Instance Methods

calc_center() click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 64
def calc_center
  return unless valid_functions?

  l1 = functions.first
  l2 = functions.last

  a1 = l1.orthogonal_slope
  b1 = l1.orthogonal_intercept
  a2 = l2.orthogonal_slope
  b2 = l2.orthogonal_intercept

  x = (b2 - b1) / (a1 - a2)
  y = (a1 * b2 - b1 * a2) / (a1 - a2)

  [x, y]
end
create_functions() click to toggle source
# File lib/geo_triangle_ext/circum_center.rb, line 53
def create_functions
  return [] unless valid_coordinates?
  ret = []
  coordinates.combination(2) do |a, b|
    f = LinearFunction.create(*([a, b].flatten))
    next unless f
    ret << f if f.valid?
  end
  ret
end