A ruby implementation of n-sphere.
In two dimension, it is a circle, and in three dimension it is a sphere. For high dimensions, the n-sphere is like a high dimension vectors, which has a distance of certain length to a point. See the above wikipedia page for detailed explanation.
gem install nsphere
irb(main):001:0> require 'rubygems' => false irb(main):002:0> require 'nsphere' => true irb(main):003:0> puts NSphere.new(coord: [3.0, 4.0]) radius: 5.0, thetas: [0.9272952180016122], coordinates: [3.0, 4.0] => nil irb(main):004:0> a = NSphere.new(coord: [3.0, 4.0]) => #<NSphere:0x00000001c2f8c0 @coordinates=[3.0, 4.0], @dim=2, @radius=5.0, @thetas=[0.9272952180016122]> irb(main):005:0> b = NSphere.new(coord: [4.0, 3.0]) => #<NSphere:0x00000001c15510 @coordinates=[4.0, 3.0], @dim=2, @radius=5.0, @thetas=[0.6435011087932844]> irb(main):006:0> a + b => #<NSphere:0x00000001c0d6d0 @coordinates=[7.0, 7.0], @dim=2, @radius=9.899494936611665, @thetas=[0.7853981633974483]>
git clone https://github.com/m00nlight/nsphere.git && cd nsphere ruby test/tc_nsphere.rb
Copyright © 2014 m00nlight. See LICENSE for details