Module: CosSinCalc::Triangle::Calculator
Instance Method Summary collapse
-
#calculate_angle_by_sides(v, r) ⇒ Object
Calculates the value of an angle when all the sides are known.
-
#calculate_side_and_angle ⇒ Object
Calculates the last unknown angle and side.
- #calculate_variables ⇒ Object
-
#equation(latex, *variables) ⇒ Object
Add a calculation step to the list of equations performed.
Instance Method Details
#calculate_angle_by_sides(v, r) ⇒ Object
Calculates the value of an angle when all the sides are known.
21 22 23 |
# File 'lib/cossincalc/triangle/calculator.rb', line 21 def calculate_angle_by_sides(v, r) acos (sq(sides(r)).inject(&:+) - sq(side(v))) / (2 * sides(r).inject(&:*)) end |
#calculate_side_and_angle ⇒ Object
Calculates the last unknown angle and side. This function is public so it is derectly callable (used with ambiguous case).
16 17 18 |
# File 'lib/cossincalc/triangle/calculator.rb', line 16 def calculate_side_and_angle calculate_two_sides end |
#calculate_variables ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/cossincalc/triangle/calculator.rb', line 6 def calculate_variables case sides.amount when 3 then calculate_three_angles when 2 then calculate_two_angles when 1 then calculate_two_sides end end |
#equation(latex, *variables) ⇒ Object
Add a calculation step to the list of equations performed.
26 27 28 29 |
# File 'lib/cossincalc/triangle/calculator.rb', line 26 def equation(latex, *variables) @equations ||= [] @equations << [latex, variables] end |