Class: GsdSphere

Inherits:
Object
  • Object
show all
Defined in:
lib/mddb/sphere.rb

Instance Method Summary collapse

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

#nodesObject



19
20
21
# File 'lib/mddb/sphere.rb', line 19

def nodes
  @nodes
end