class Cartesius::Circumference
Public Class Methods
by_definition(center:, radius:)
click to toggle source
# File lib/cartesius/circumference.rb, line 18 def self.by_definition(center:, radius:) if radius <= 0 raise ArgumentError.new('Radius must be positive!') end build_by(center, radius) end
by_diameter(diameter:)
click to toggle source
# File lib/cartesius/circumference.rb, line 26 def self.by_diameter(diameter:) center = diameter.mid radius = Rational(diameter.length, 2) build_by(center, radius) end
by_points(point1:, point2:, point3:)
click to toggle source
# File lib/cartesius/circumference.rb, line 33 def self.by_points(point1:, point2:, point3:) alfa, beta, gamma = Cramer.solution3( [point1.x, point1.y, 1], [point2.x, point2.y, 1], [point3.x, point3.y, 1], [-(point1.x ** 2 + point1.y ** 2), -(point2.x ** 2 + point2.y ** 2), -(point3.x ** 2 + point3.y ** 2)] ) new(x: alfa, y: beta, k: gamma) rescue raise ArgumentError.new('Invalid points!') end
goniometric()
click to toggle source
# File lib/cartesius/circumference.rb, line 45 def self.goniometric build_by(Point.origin, 1) end
new(x:, y:, k:)
click to toggle source
Conic Conic equation type: x^2 + y^2 + dx + ey + f = 0
# File lib/cartesius/circumference.rb, line 13 def initialize(x:, y:, k:) @x2_coeff, @y2_coeff, @x_coeff, @y_coeff, @k_coeff = normalize(1, 1, x, y, k) validation end
Private Class Methods
build_by(center, radius)
click to toggle source
# File lib/cartesius/circumference.rb, line 71 def self.build_by(center, radius) new(x: -2 * center.x, y: -2 * center.y, k: center.x ** 2 + center.y ** 2 - radius.to_r ** 2) end
Public Instance Methods
==(circumference)
click to toggle source
# File lib/cartesius/circumference.rb, line 66 def == (circumference) circumference.instance_of?(self.class) && circumference.center == center && circumference.radius == radius end
congruent?(circumference)
click to toggle source
# File lib/cartesius/circumference.rb, line 61 def congruent?(circumference) circumference.instance_of?(self.class) && circumference.radius == radius end
eccentricity()
click to toggle source
# File lib/cartesius/circumference.rb, line 57 def eccentricity 0 end
goniometric?()
click to toggle source
# File lib/cartesius/circumference.rb, line 49 def goniometric? self == Circumference.goniometric end
radius()
click to toggle source
# File lib/cartesius/circumference.rb, line 53 def radius Math.sqrt(a2) end
Private Instance Methods
validation()
click to toggle source
# File lib/cartesius/circumference.rb, line 79 def validation if determinator <= @k_coeff raise ArgumentError.new('Invalid coefficients!') end end