Class: Pulo::Trapezoid
- Inherits:
-
Object
- Object
- Pulo::Trapezoid
- Includes:
- Figure2D
- Defined in:
- lib/pulo/figure/figure2d.rb
Overview
isoscelese only
Instance Attribute Summary collapse
-
#angle ⇒ Object
readonly
Returns the value of attribute angle.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
-
#side_triangle ⇒ Object
readonly
Returns the value of attribute side_triangle.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Attributes included from Figure2D
Instance Method Summary collapse
- #extrusion_figure ⇒ Object
-
#initialize(angle: nil, height: nil, base: nil, area: nil, top: nil) ⇒ Trapezoid
constructor
A new instance of Trapezoid.
Methods included from Figure2D
Methods included from Quantity_Checker
Constructor Details
#initialize(angle: nil, height: nil, base: nil, area: nil, top: nil) ⇒ Trapezoid
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/pulo/figure/figure2d.rb', line 213 def initialize(angle: nil,height: nil,base: nil, area: nil,top: nil) quantity_check [angle,Angle] ,[height,Length] , [base,Length] , [top,Length], [area,Area] raise 'Need more arguments for trapezoid' unless ((angle and height and (base or top) or (base and top and height) or (area and base and top))) if angle and height and (base or top) @angle=angle; @height=height @side_triangle=Triangle.new(angles: [@angle,nil,Angle.pi/2], lengths: [@height,nil,nil]) @side=@side_triangle.lengths[2] if base @base=base; @top=@base-@side_triangle.lengths[0]*2 else #top @top=top; @base=@top+@side_triangle.lengths[0]*2 end @area=(@base+@top)/2*@height elsif base and top and height @height=height;@base=base;@top=top @side_triangle=Triangle.new(lengths: [@height,(@base-@top)/2,nil],angles: [Angle.pi/2]) @side=@side_triangle.lengths[2] @area=(@base+@top)/2*@height elsif area and base and top @area=area; @base=base; @top=top @height=(@area*2)/(@base+@top) @side_triangle=Triangle.new(angles: [Angle.pi/2], lengths: [@height,(@base-@top)/2]) @side=@side_triangle.lengths[2] elsif area and angle and base #TODO: area and angle and base #@angle=angle; @area=area; @base=base #@height=(Math.sqrt((@base**2)+(4*Math.tan(@angle)*@area))-@base)/(2*Math.tan(@angle)) #@side_triangle=Triangle.new(angles: [@angle,nil,Angle.pi/2], lengths: [@height,nil,nil]) #@side=@side_triangle.lengths[2] #@top=@base+@side_triangle.lengths[0]*2 end @perimeter=@base+@top+(@side*2) end |
Instance Attribute Details
#angle ⇒ Object (readonly)
Returns the value of attribute angle.
209 210 211 |
# File 'lib/pulo/figure/figure2d.rb', line 209 def angle @angle end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
209 210 211 |
# File 'lib/pulo/figure/figure2d.rb', line 209 def base @base end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
209 210 211 |
# File 'lib/pulo/figure/figure2d.rb', line 209 def height @height end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
209 210 211 |
# File 'lib/pulo/figure/figure2d.rb', line 209 def side @side end |
#side_triangle ⇒ Object (readonly)
Returns the value of attribute side_triangle.
209 210 211 |
# File 'lib/pulo/figure/figure2d.rb', line 209 def side_triangle @side_triangle end |
#top ⇒ Object (readonly)
Returns the value of attribute top.
209 210 211 |
# File 'lib/pulo/figure/figure2d.rb', line 209 def top @top end |
Instance Method Details
#extrusion_figure ⇒ Object
210 211 212 |
# File 'lib/pulo/figure/figure2d.rb', line 210 def extrusion_figure TrapezoidalPrism end |