class HyperSphere

Attributes

center[R]
pct_error[RW]
radius[R]

Public Class Methods

help() click to toggle source
# File lib/zadt/HelpModules/Functionality/Geometrics/hypersphere.rb, line 2
def self.help
  Sphere.show_help_message
end
new(radius = 1, center = [0,0,0,0], pct_error = 1) click to toggle source
# 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

Private Class Methods

show_help_message() click to toggle source
# File lib/zadt/HelpModules/Functionality/Geometrics/hypersphere.rb, line 12
def self.show_help_message
  Zadt::ADT::show_hypersphere_help_message
end

Public Instance Methods

equation() click to toggle source
# File lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb, line 29
def equation
  dims = @center.dims
  return circle_equation if is_a?(Circle)
  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() click to toggle source
# File lib/zadt/HelpModules/Functionality/Geometrics/hypersphere.rb, line 6
def help
  Sphere.help
end
how_far(point) click to toggle source
# File lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb, line 25
def how_far(point)
  (@radius - Zadt::Universe.distance(@center, point)).abs
end
inside?(point) click to toggle source
# File lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb, line 17
def inside?(point)
  Zadt::Universe.distance(@center, point) <= @radius
end
on?(point) click to toggle source
# File lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb, line 13
def on?(point)
  Zadt::Universe.distance(@center, point).round(2) == radius.round(2)
end
outside?(point) click to toggle source
# File lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb, line 21
def outside?(point)
  !inside?(point)
end

Private Instance Methods

dim_check(num) click to toggle source
# File lib/zadt/AbstractDataTypes/Geometrics/hypersphere.rb, line 56
def dim_check(num)
  raise "dimension error" unless num == @center.dims
end