Class: HyperSphere
- Inherits:
-
Object
- Object
- HyperSphere
- Defined in:
- lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb
Instance Attribute Summary collapse
-
#center ⇒ Object
readonly
Returns the value of attribute center.
-
#pct_error ⇒ Object
Returns the value of attribute pct_error.
-
#radius ⇒ Object
readonly
Returns the value of attribute radius.
Class Method Summary collapse
Instance Method Summary collapse
- #equation ⇒ Object
- #help ⇒ Object
- #how_far(point) ⇒ Object
-
#initialize(radius = 1, center = [0,0,0,0], pct_error = 1) ⇒ HyperSphere
constructor
A new instance of HyperSphere.
- #inside?(point) ⇒ Boolean
- #on?(point) ⇒ Boolean
- #outside?(point) ⇒ Boolean
Constructor Details
#initialize(radius = 1, center = [0,0,0,0], pct_error = 1) ⇒ HyperSphere
Returns a new instance of HyperSphere.
7 8 9 10 11 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 7 def initialize(radius = 1, center = [0,0,0,0], pct_error = 1) @radius = radius @center = Point.new(center) @pct_error = pct_error end |
Instance Attribute Details
#center ⇒ Object (readonly)
Returns the value of attribute center.
4 5 6 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 4 def center @center end |
#pct_error ⇒ Object
Returns the value of attribute pct_error.
5 6 7 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 5 def pct_error @pct_error end |
#radius ⇒ Object (readonly)
Returns the value of attribute radius.
4 5 6 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 4 def radius @radius end |
Class Method Details
.help ⇒ Object
13 14 15 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 13 def self.help Sphere. end |
Instance Method Details
#equation ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 37 def equation dims = @center.dims return circle_equation if dims == 2 center_point = @center.dup # Only get the variables used in that dimension coord_names = ("a".."z").to_a.slice(-dims, dims) center_point.coords.each_with_index do |center_coord, index| if center_coord == 0 # coord_name is fine elsif center_coord < 0 coord_names[index] = "(#{coord_names[index]} + #{-center_coord})" else coord_names[index] = "(#{coord_names[index]} - #{center_coord})" end end final_string = "" (dims - 1).times do |index| final_string += "#{coord_names[index]}^2 + " end final_string += "#{coord_names[dims - 1]}^2" final_string += " = " final_string += "#{@radius ** 2}" final_string end |
#help ⇒ Object
17 18 19 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 17 def help Sphere.help end |
#how_far(point) ⇒ Object
33 34 35 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 33 def how_far(point) (@radius - Zadt::Universe.distance(@center, point)).abs end |
#inside?(point) ⇒ Boolean
25 26 27 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 25 def inside?(point) Zadt::Universe.distance(@center, point) <= @radius end |
#on?(point) ⇒ Boolean
21 22 23 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 21 def on?(point) Zadt::Universe.distance(@center, point).round(2) == radius.round(2) end |
#outside?(point) ⇒ Boolean
29 30 31 |
# File 'lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb', line 29 def outside?(point) !inside?(point) end |