1- # Circumcircle from 3 points
1+ # frozen_string_literal: true
22require 'matrix'
33
4+ # Circumcircle from 3 points
45class Circumcircle
56 attr_reader :center , :radius , :points
67 def initialize ( points )
@@ -19,25 +20,19 @@ def calculate
1920
2021 def am
2122 2 * Matrix [
22- [ points [ 0 ] . x , points [ 0 ] . y , 1 ] ,
23- [ points [ 1 ] . x , points [ 1 ] . y , 1 ] ,
24- [ points [ 2 ] . x , points [ 2 ] . y , 1 ]
23+ *points . map { |pt | [ pt . x , pt . y , 1 ] }
2524 ] . determinant
2625 end
2726
2827 def bx
2928 -Matrix [
30- [ points [ 0 ] . x * points [ 0 ] . x + points [ 0 ] . y * points [ 0 ] . y , points [ 0 ] . y , 1 ] ,
31- [ points [ 1 ] . x * points [ 1 ] . x + points [ 1 ] . y * points [ 1 ] . y , points [ 1 ] . y , 1 ] ,
32- [ points [ 2 ] . x * points [ 2 ] . x + points [ 2 ] . y * points [ 2 ] . y , points [ 2 ] . y , 1 ]
29+ *points . map { |pt | [ pt . x * pt . x + pt . y * pt . y , pt . y , 1 ] }
3330 ] . determinant
3431 end
3532
3633 def by
3734 Matrix [
38- [ points [ 0 ] . x * points [ 0 ] . x + points [ 0 ] . y * points [ 0 ] . y , points [ 0 ] . x , 1 ] ,
39- [ points [ 1 ] . x * points [ 1 ] . x + points [ 1 ] . y * points [ 1 ] . y , points [ 1 ] . x , 1 ] ,
40- [ points [ 2 ] . x * points [ 2 ] . x + points [ 2 ] . y * points [ 2 ] . y , points [ 2 ] . x , 1 ]
35+ *points . map { |pt | [ pt . x * pt . x + pt . y * pt . y , pt . x , 1 ] }
4136 ] . determinant
4237 end
4338end
0 commit comments