Sha256: 75078b5511841736e3cfb35a75673299bb4342e1266b4d146117f98f0ce66504
Contents?: true
Size: 1.59 KB
Versions: 6
Compression:
Stored size: 1.59 KB
Contents
require_relative 'point.rb' class HyperSphere attr_reader :radius, :center attr_accessor :pct_error def initialize(radius = 1, center = [0,0,0,0], pct_error = 1) @radius = radius @center = Point.new(center) @pct_error = pct_error end def self.help Sphere.show_help_message end def help Sphere.help end def on?(point) Zadt::Universe.distance(@center, point).round(2) == radius.round(2) end def inside?(point) Zadt::Universe.distance(@center, point) <= @radius end def outside?(point) !inside?(point) end def how_far(point) (@radius - Zadt::Universe.distance(@center, point)).abs end 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 private def dim_check(num) raise "dimension error" unless num == @center.dims end def self.show_help_message Zadt::ADT::show_hypersphere_help_message end end
Version data entries
6 entries across 6 versions & 1 rubygems