gss_generator 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/gss_gen +7 -4
- data/lib/gss.rb +1 -1
- data/lib/gss/generator.rb +45 -0
- data/lib/gss/polar_point.rb +11 -6
- data/lib/gss/version.rb +1 -1
- metadata +3 -3
- data/lib/gss/gss.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcb0eb5d3947f39d7d397b800ecab0c7cec2de3a
|
4
|
+
data.tar.gz: 57a4f152cf75ecdd5b4fc699d1a4772ac7d85467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a5bf0fc925400d7eed9044ac3b0f6e052883bf7d59a54e58b13434b56cab265fd3112c52eab2b71b060f5c8700f82ff804af6353387a715d127ac37bb76e120
|
7
|
+
data.tar.gz: 926e844d43ef31040c1c8db4136f79dca04409c0232fa73cc0b7127452f5eb3a9dbd75d52899ac7bc0d3f9c8fdf908c0e6ae7847e2b971b2c859151d328df2da
|
data/exe/gss_gen
CHANGED
@@ -12,6 +12,9 @@ opts.banner = "Generate points with uniform distribution on the sphere."
|
|
12
12
|
opts.on("-c", "--cartesian", "Cartesian coordinate."){|v|
|
13
13
|
options[:cartesian] = true
|
14
14
|
}
|
15
|
+
opts.on("-r", "--relocate", "Relocate first and last point."){|v|
|
16
|
+
options[:relocation] = true
|
17
|
+
}
|
15
18
|
opts.on_tail("-h", "--help", "Show this message."){|v|
|
16
19
|
print opts.help
|
17
20
|
exit
|
@@ -25,13 +28,13 @@ opts.parse!
|
|
25
28
|
r = ARGV.shift.to_f
|
26
29
|
n = ARGV.shift.to_i
|
27
30
|
|
28
|
-
gss = GSS::
|
29
|
-
points = gss.generate(
|
31
|
+
gss = GSS::Generator.new
|
32
|
+
points = gss.generate(n, options[:relocation])
|
30
33
|
points.each do |p|
|
31
34
|
if options[:cartesian]
|
32
|
-
coord = p.to_cartesian
|
35
|
+
coord = p.to_cartesian.map{|c| c * r }
|
33
36
|
print coord.to_csv
|
34
37
|
else
|
35
|
-
print [
|
38
|
+
print [r, p.theta, p.phi].to_csv
|
36
39
|
end
|
37
40
|
end
|
data/lib/gss.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Generate points that distributed on unit sphere with Generalized Spiral Set.
|
4
|
+
# cf. https://www.jstage.jst.go.jp/article/geoinformatics/12/1/12_1_3/_article/-char/ja/
|
5
|
+
#
|
6
|
+
|
7
|
+
require "gss/polar_point"
|
8
|
+
|
9
|
+
|
10
|
+
module GSS
|
11
|
+
|
12
|
+
class Generator
|
13
|
+
def generate(n, relocation = false)
|
14
|
+
theta_1 = Math::PI
|
15
|
+
phi_1 = 0.0
|
16
|
+
|
17
|
+
points = []
|
18
|
+
points << PolarPoint.new(theta_1, phi_1)
|
19
|
+
2.upto(n) do |k|
|
20
|
+
h_k = -1.0 + 2.0 * (k - 1) / (n - 1)
|
21
|
+
theta_k = Math.acos(h_k)
|
22
|
+
phi_k = points.last.phi + 3.6 / Math.sqrt(n) * 1 / Math.sqrt(1 - h_k ** 2)
|
23
|
+
phi_k = phi_k.infinite? ? 0.0 : phi_k % (Math::PI * 2.0)
|
24
|
+
points << PolarPoint.new(theta_k, phi_k)
|
25
|
+
end
|
26
|
+
|
27
|
+
if relocation
|
28
|
+
points[0] = relocate(points[1], points[2], points[4], points[5], points[6])
|
29
|
+
points[-1] = relocate(points[-2], points[-3], points[-5], points[-6], points[-7])
|
30
|
+
end
|
31
|
+
|
32
|
+
points
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def relocate(p1, p2, p3, p4, p5)
|
38
|
+
c = [p1, p2, p3, p4, p5].map{|p| p.to_cartesian }
|
39
|
+
c = c.transpose.map{|l| l.inject(&:+) / 5.0 }
|
40
|
+
PolarPoint.from_cartesian(c[0], c[1], c[2])
|
41
|
+
end
|
42
|
+
|
43
|
+
end # of class Generator
|
44
|
+
|
45
|
+
end # of module GSS
|
data/lib/gss/polar_point.rb
CHANGED
@@ -4,20 +4,25 @@
|
|
4
4
|
module GSS
|
5
5
|
|
6
6
|
class PolarPoint
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :theta, :phi
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@r = r
|
9
|
+
def initialize(theta, phi)
|
11
10
|
@theta = theta
|
12
11
|
@phi = phi
|
13
12
|
end
|
14
13
|
|
15
14
|
def to_cartesian
|
16
|
-
x =
|
17
|
-
y =
|
18
|
-
z =
|
15
|
+
x = Math.sin(@theta) * Math.cos(@phi)
|
16
|
+
y = Math.sin(@theta) * Math.sin(@phi)
|
17
|
+
z = Math.cos(@theta)
|
19
18
|
[x, y, z]
|
20
19
|
end
|
20
|
+
|
21
|
+
def self.from_cartesian(x, y, z)
|
22
|
+
theta = Math.acos(z / Math.sqrt(x * x + y * y + z * z))
|
23
|
+
phi = Math.atan2(y, x)
|
24
|
+
self.new(theta, phi)
|
25
|
+
end
|
21
26
|
end # of class PolarPoint
|
22
27
|
|
23
28
|
end # of module GSS
|
data/lib/gss/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gss_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takatoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -57,7 +57,7 @@ files:
|
|
57
57
|
- exe/gss_gen
|
58
58
|
- gss_generator.gemspec
|
59
59
|
- lib/gss.rb
|
60
|
-
- lib/gss/
|
60
|
+
- lib/gss/generator.rb
|
61
61
|
- lib/gss/polar_point.rb
|
62
62
|
- lib/gss/version.rb
|
63
63
|
homepage: https://github.com/takatoh/gss_generator
|
data/lib/gss/gss.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "gss/polar_point"
|
4
|
-
|
5
|
-
|
6
|
-
module GSS
|
7
|
-
|
8
|
-
class GSS
|
9
|
-
def generate(r, n)
|
10
|
-
theta_1 = Math::PI
|
11
|
-
phi_1 = 0.0
|
12
|
-
|
13
|
-
points = []
|
14
|
-
points << PolarPoint.new(r, theta_1, phi_1)
|
15
|
-
2.upto(n) do |k|
|
16
|
-
h_k = -1.0 + 2.0 * (k - 1) / (n - 1)
|
17
|
-
theta_k = Math.acos(h_k)
|
18
|
-
phi_k = points.last.phi + 3.6 / Math.sqrt(n) * 1 / Math.sqrt(1 - h_k ** 2)
|
19
|
-
phi_k = phi_k.infinite? ? 0.0 : phi_k % (Math::PI * 2.0)
|
20
|
-
points << PolarPoint.new(r, theta_k, phi_k)
|
21
|
-
end
|
22
|
-
|
23
|
-
points
|
24
|
-
end
|
25
|
-
end # of class GSS
|
26
|
-
|
27
|
-
end # of module GSS
|