Class: Cartesius::Hyperbola
- Inherits:
-
Object
- Object
- Cartesius::Hyperbola
- Includes:
- Determinator, Numerificator
- Defined in:
- lib/cartesius/hyperbola.rb
Class Method Summary collapse
- .by_axes(transverse_axis:, not_transverse_axis:) ⇒ Object
- .by_definition(focus1:, focus2:, distance:) ⇒ Object
- .by_points(center:, vertex:, point:) ⇒ Object
Instance Method Summary collapse
- #==(hyperbola) ⇒ Object
- #ascending_asymptote ⇒ Object
- #congruent?(hyperbola) ⇒ Boolean
- #descending_asymptote ⇒ Object
- #distance ⇒ Object
- #eccentricity ⇒ Object
- #equilateral? ⇒ Boolean
- #focal_axis ⇒ Object
- #focus1 ⇒ Object
- #focus2 ⇒ Object
-
#initialize(x2:, y2:, x:, y:, k:) ⇒ Hyperbola
constructor
Conic equation type: ax^2 + by^2 + dx + ey + f = 0.
- #not_transverse_axis ⇒ Object
- #transverse_axis ⇒ Object
- #vertices ⇒ Object
Constructor Details
#initialize(x2:, y2:, x:, y:, k:) ⇒ Hyperbola
Conic equation type: ax^2 + by^2 + dx + ey + f = 0
18 19 20 21 |
# File 'lib/cartesius/hyperbola.rb', line 18 def initialize(x2:, y2:, x:, y:, k:) @x2_coeff, @y2_coeff, @x_coeff, @y_coeff, @k_coeff = normalize(x2, y2, x, y, k) validation end |
Class Method Details
.by_axes(transverse_axis:, not_transverse_axis:) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cartesius/hyperbola.rb', line 53 def self.by_axes(transverse_axis:, not_transverse_axis:) if transverse_axis == not_transverse_axis raise ArgumentError.new('Axes must be different!') end if transverse_axis.inclined? or not_transverse_axis.inclined? raise ArgumentError.new('Axes must not be inclined!') end if transverse_axis.horizontal? and not_transverse_axis.horizontal? raise ArgumentError.new('Axes can not be both horizontal!') end if transverse_axis.vertical? and not_transverse_axis.vertical? raise ArgumentError.new('Axes can not be both vertical!') end if transverse_axis.mid != not_transverse_axis.mid raise ArgumentError.new('Axes must be the same mid point!') end if transverse_axis.horizontal? a2 = Rational(transverse_axis.length, 2)**2 b2 = Rational(not_transverse_axis.length, 2)**2 position = RIGHT_POSITION else a2 = Rational(not_transverse_axis.length, 2)**2 b2 = Rational(transverse_axis.length, 2)**2 position = UP_POSITION end center = transverse_axis.mid build_by(a2, b2, center, position) end |
.by_definition(focus1:, focus2:, distance:) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cartesius/hyperbola.rb', line 23 def self.by_definition(focus1:, focus2:, distance:) if focus1 == focus2 raise ArgumentError.new('Focus points must be different!') end focal_axis = Segment.new(extreme1: focus1, extreme2: focus2) if focal_axis.inclined? raise ArgumentError.new('Focal axis must not be inclined!') end if distance >= focal_axis.length raise ArgumentError.new('Difference between distances must be less than focal distance!') end c2 = Rational(focal_axis.length, 2)**2 if focal_axis.horizontal? a2 = Rational(distance, 2)**2 b2 = c2 - a2 position = RIGHT_POSITION else b2 = Rational(distance, 2)**2 a2 = c2 - b2 position = UP_POSITION end center = focal_axis.mid build_by(a2, b2, center, position) end |
.by_points(center:, vertex:, point:) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cartesius/hyperbola.rb', line 89 def self.by_points(center:, vertex:, point:) if center == vertex or center == point or vertex == point raise ArgumentError.new('Points must be different!') end semi_axis = Segment.new(extreme1: center, extreme2: vertex) if semi_axis.inclined? raise ArgumentError.new('Vertex must be aligned with center!') end if semi_axis.horizontal? position = RIGHT_POSITION else position = UP_POSITION end shifted1 = Point.new(x: vertex.x - center.x, y: vertex.y - center.y) shifted2 = Point.new(x: point.x - center.x, y: point.y - center.y) begin alfa, beta = Cramer.solution2( [shifted1.x**2, -shifted1.y**2], [shifted2.x**2, -shifted2.y**2], [position, position] ) rescue raise ArgumentError.new('Center, vertex and point are not valid!') end a2 = Rational(1, alfa) b2 = Rational(1, beta) build_by(a2, b2, center, position) end |
Instance Method Details
#==(hyperbola) ⇒ Object
188 189 190 191 |
# File 'lib/cartesius/hyperbola.rb', line 188 def == (hyperbola) hyperbola.instance_of?(self.class) and hyperbola.focus1 == focus1 and hyperbola.focus2 == focus2 and hyperbola.distance == distance end |
#ascending_asymptote ⇒ Object
171 172 173 |
# File 'lib/cartesius/hyperbola.rb', line 171 def ascending_asymptote Line.create(slope: Rational(b, a), known_term: center.y - center.x * Rational(b, a)) end |
#congruent?(hyperbola) ⇒ Boolean
183 184 185 186 |
# File 'lib/cartesius/hyperbola.rb', line 183 def congruent?(hyperbola) hyperbola.instance_of?(self.class) and hyperbola.eccentricity == eccentricity end |
#descending_asymptote ⇒ Object
175 176 177 |
# File 'lib/cartesius/hyperbola.rb', line 175 def descending_asymptote Line.create(slope: -Rational(b, a), known_term: center.y + center.x * Rational(b, a)) end |
#distance ⇒ Object
138 139 140 |
# File 'lib/cartesius/hyperbola.rb', line 138 def distance discriminating(lambda {2 * a}, lambda {2 * b}) end |
#eccentricity ⇒ Object
167 168 169 |
# File 'lib/cartesius/hyperbola.rb', line 167 def eccentricity Rational(focal_axis.length, transverse_axis.length) end |
#equilateral? ⇒ Boolean
179 180 181 |
# File 'lib/cartesius/hyperbola.rb', line 179 def equilateral? a2 == b2 end |
#focal_axis ⇒ Object
142 143 144 |
# File 'lib/cartesius/hyperbola.rb', line 142 def focal_axis Segment.new(extreme1: focus1, extreme2: focus2) end |
#focus1 ⇒ Object
124 125 126 127 128 129 |
# File 'lib/cartesius/hyperbola.rb', line 124 def focus1 discriminating( lambda {Point.new(x: center.x + c, y: center.y)}, lambda {Point.new(x: center.x, y: center.y + c)} ) end |
#focus2 ⇒ Object
131 132 133 134 135 136 |
# File 'lib/cartesius/hyperbola.rb', line 131 def focus2 discriminating( lambda {Point.new(x: center.x - c, y: center.y)}, lambda {Point.new(x: center.x, y: center.y - c)} ) end |
#not_transverse_axis ⇒ Object
153 154 155 156 157 158 |
# File 'lib/cartesius/hyperbola.rb', line 153 def not_transverse_axis discriminating( lambda {Segment.new(extreme1: Point.new(x: center.x, y: center.y - b), extreme2: Point.new(x: center.x, y: center.y + b))}, lambda {Segment.new(extreme1: Point.new(x: center.x - a, y: center.y), extreme2: Point.new(x: center.x + a, y: center.y))} ) end |
#transverse_axis ⇒ Object
146 147 148 149 150 151 |
# File 'lib/cartesius/hyperbola.rb', line 146 def transverse_axis discriminating( lambda {Segment.new(extreme1: Point.new(x: center.x - a, y: center.y), extreme2: Point.new(x: center.x + a, y: center.y))}, lambda {Segment.new(extreme1: Point.new(x: center.x, y: center.y - b), extreme2: Point.new(x: center.x, y: center.y + b))}, ) end |
#vertices ⇒ Object
160 161 162 163 164 165 |
# File 'lib/cartesius/hyperbola.rb', line 160 def vertices discriminating( lambda {[Point.new(x: center.x - a, y: center.y), Point.new(x: center.x + a, y: center.y)]}, lambda {[Point.new(x: center.x, y: center.y - b), Point.new(x: center.x, y: center.y + b)]} ) end |