1
- # Circumcircle from 3 points
1
+ # frozen_string_literal: true
2
2
require 'matrix'
3
3
4
+ # Circumcircle from 3 points
4
5
class Circumcircle
5
6
attr_reader :center , :radius , :points
6
7
def initialize ( points )
@@ -19,25 +20,19 @@ def calculate
19
20
20
21
def am
21
22
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 ] }
25
24
] . determinant
26
25
end
27
26
28
27
def bx
29
28
-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 ] }
33
30
] . determinant
34
31
end
35
32
36
33
def by
37
34
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 ] }
41
36
] . determinant
42
37
end
43
38
end
0 commit comments