Class: CrystalScad::Extras::Triangle
- Inherits:
-
Object
- Object
- CrystalScad::Extras::Triangle
- Defined in:
- lib/crystalscad/Extras.rb
Overview
This currently can solve triangels knowing 1 side and 2 angels
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#alpha ⇒ Object
Returns the value of attribute alpha.
-
#b ⇒ Object
Returns the value of attribute b.
-
#beta ⇒ Object
Returns the value of attribute beta.
-
#c ⇒ Object
Returns the value of attribute c.
-
#gamma ⇒ Object
Returns the value of attribute gamma.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Triangle
constructor
A new instance of Triangle.
- #solve ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Triangle
Returns a new instance of Triangle.
7 8 9 10 11 12 13 14 15 |
# File 'lib/crystalscad/Extras.rb', line 7 def initialize(args={}) @alpha = args[:alpha] @beta = args[:beta] @gamma = args[:gamma] @a = args[:a] @b = args[:b] @c = args[:c] solve end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
6 7 8 |
# File 'lib/crystalscad/Extras.rb', line 6 def a @a end |
#alpha ⇒ Object
Returns the value of attribute alpha.
6 7 8 |
# File 'lib/crystalscad/Extras.rb', line 6 def alpha @alpha end |
#b ⇒ Object
Returns the value of attribute b.
6 7 8 |
# File 'lib/crystalscad/Extras.rb', line 6 def b @b end |
#beta ⇒ Object
Returns the value of attribute beta.
6 7 8 |
# File 'lib/crystalscad/Extras.rb', line 6 def beta @beta end |
#c ⇒ Object
Returns the value of attribute c.
6 7 8 |
# File 'lib/crystalscad/Extras.rb', line 6 def c @c end |
#gamma ⇒ Object
Returns the value of attribute gamma.
6 7 8 |
# File 'lib/crystalscad/Extras.rb', line 6 def gamma @gamma end |
Instance Method Details
#solve ⇒ Object
17 18 19 20 21 22 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 52 53 54 55 56 |
# File 'lib/crystalscad/Extras.rb', line 17 def solve # see if we have two angles, so we know the third one if @alpha == nil and @beta != nil and @gamma != nil @alpha = 180 - @beta - @gamma elsif @alpha != nil and @beta == nil and @gamma != nil @beta = 180 - @alpha - @gamma elsif @alpha != nil and @beta != nil and @gamma == nil @gamma = 180 - @alpha - @beta end if @alpha != nil and @beta != nil and @gamma != nil if @a == nil if @b != nil @a = (@b / Math::sin(radians(@beta))) * Math::sin(radians(@alpha)) elsif @c != nil @a = (@c / Math::sin(radians(@gamma))) * Math::sin(radians(@alpha)) end end if @b == nil if @a != nil @b = (@a / Math::sin(radians(@alpha))) * Math::sin(radians(@beta)) elsif @c != nil @b = (@c / Math::sin(radians(@gamma))) * Math::sin(radians(@beta)) end end if @c == nil if @a != nil @c = (@a / Math::sin(radians(@alpha))) * Math::sin(radians(@gamma)) elsif @b != nil @c = (@b / Math::sin(radians(@beta))) * Math::sin(radians(@gamma)) end end end end |