Class: GsdSphere
- Inherits:
-
Object
- Object
- GsdSphere
- Defined in:
- lib/mddb/sphere.rb
Instance Method Summary collapse
- #create(points) ⇒ Object
-
#initialize(points) ⇒ GsdSphere
constructor
A new instance of GsdSphere.
- #nodes ⇒ Object
Constructor Details
#initialize(points) ⇒ GsdSphere
Returns a new instance of GsdSphere.
2 3 4 5 |
# File 'lib/mddb/sphere.rb', line 2 def initialize(points) @nodes = [] self.create points end |
Instance Method Details
#create(points) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mddb/sphere.rb', line 7 def create points n = points inc = Math::PI*(3-Math.sqrt(5)) off = 2.0/n (0..(n-1)).each do |i| y = i * off - 1 + (off/2) r = Math.sqrt(1-(y*y)) phi = i * inc @nodes.push (Point[Math.cos(phi)*r, Math.sin(phi)*r, y]) end end |
#nodes ⇒ Object
19 20 21 |
# File 'lib/mddb/sphere.rb', line 19 def nodes @nodes end |