Class: Cartesius::Parabola
- Inherits:
-
Object
- Object
- Cartesius::Parabola
- Includes:
- Numerificator
- Defined in:
- lib/cartesius/parabola.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(parabola) ⇒ Object
- #congruent?(parabola) ⇒ Boolean
- #directrix ⇒ Object
- #eccentricity ⇒ Object
- #focus ⇒ Object
-
#initialize(x2:, x:, k:) ⇒ Parabola
constructor
Conic Conic equation type: ax^2 + dx - y + f = 0.
- #symmetry_axis ⇒ Object
- #to_equation ⇒ Object
- #vertex ⇒ Object
Constructor Details
#initialize(x2:, x:, k:) ⇒ Parabola
Conic Conic equation type: ax^2 + dx - y + f = 0
13 14 15 16 |
# File 'lib/cartesius/parabola.rb', line 13 def initialize(x2:, x:, k:) @x2_coeff, @x_coeff, @y_coeff, @k_coeff = x2.to_r, x.to_r, -1, k.to_r validation end |
Class Method Details
.by_definition(directrix:, focus:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cartesius/parabola.rb', line 18 def self.by_definition(directrix:, focus:) if directrix.include?(focus) raise ArgumentError.new('Focus belongs to directrix!') end unless directrix.horizontal? raise ArgumentError.new('Directrix is not parallel to x-axis!') end a = Rational(1, 2 * (focus.y - directrix.y_intercept)) b = -2 * a * focus.x c = a * (focus.x ** 2) + focus.y - Rational(1, 4 * a) new(x2: a, x: b, k: c) end |
.by_points(point1:, point2:, point3:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cartesius/parabola.rb', line 34 def self.by_points(point1:, point2:, point3:) a, b, c = Cramer.solution3( [point1.x ** 2, point1.x, 1], [point2.x ** 2, point2.x, 1], [point3.x ** 2, point3.x, 1], [point1.y, point2.y, point3.y] ) new(x2: a, x: b, k: c) rescue raise ArgumentError.new('Invalid points!') end |
Instance Method Details
#==(parabola) ⇒ Object
78 79 80 81 |
# File 'lib/cartesius/parabola.rb', line 78 def == (parabola) parabola.instance_of?(self.class) && parabola.focus == focus && parabola.directrix == directrix end |
#congruent?(parabola) ⇒ Boolean
73 74 75 76 |
# File 'lib/cartesius/parabola.rb', line 73 def congruent?(parabola) parabola.instance_of?(self.class) && parabola.eccentricity == eccentricity end |
#directrix ⇒ Object
47 48 49 |
# File 'lib/cartesius/parabola.rb', line 47 def directrix Line.horizontal(known_term: Rational(-delta - 1, 4 * @x2_coeff)) end |
#eccentricity ⇒ Object
63 64 65 |
# File 'lib/cartesius/parabola.rb', line 63 def eccentricity @x2_coeff.abs end |
#focus ⇒ Object
51 52 53 |
# File 'lib/cartesius/parabola.rb', line 51 def focus Point.new(x: Rational(-@x_coeff, 2 * @x2_coeff), y: Rational(1 - delta, 4 * @x2_coeff)) end |
#symmetry_axis ⇒ Object
59 60 61 |
# File 'lib/cartesius/parabola.rb', line 59 def symmetry_axis Line.vertical(known_term: Rational(-@x_coeff, 2* @x2_coeff)) end |
#to_equation ⇒ Object
67 68 69 70 71 |
# File 'lib/cartesius/parabola.rb', line 67 def to_equation equationfy( 'x^2' => @x2_coeff, 'x' => @x_coeff, 'y' => -1, '1' => @k_coeff ) end |