gss_generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4868e0b7c76222b5191410a95508ad4bbfedae3c
4
+ data.tar.gz: 101d123737d65b5b2b7fdc72b6e302c45e53e987
5
+ SHA512:
6
+ metadata.gz: 4b8bdf6afa55a7244d59e63d97d3c736d40bce949b7a90caa012c85847b24998d685f250a5b8c693d36b907e48792d9ae955756d28b6d846d3b123d780080634
7
+ data.tar.gz: 80920acc43a63a223fe68ea43a7cf02a5404df5c74667d74a22e77a9d46e4198f2af8c00163ff081720a0bea1c97ca66ee5ba62f6a399e660cdb706734e30a07
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bak
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gss.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 takatoh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # GSS Generator
2
+
3
+ GSS Generator provide generating a set of points that are uniform points on a sphere, with
4
+ generalized spiral set.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'gss_generator'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install gss_generator
21
+
22
+ ## Usage
23
+
24
+ ### As command
25
+
26
+ $ gss_gen <r> <N>
27
+
28
+ r is radius of spher and N is number of points you want. Output points in polar coordinates into CSV.
29
+ If you want in cartesian coordinates:
30
+
31
+ $ gss_gen --cartesian <r> <N>
32
+
33
+ For more information, use --help option.
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/takatoh/gss_generator.
44
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gss"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'gss'
5
+ require 'optparse'
6
+ require 'csv'
7
+
8
+
9
+ options = {}
10
+ opts = OptionParser.new
11
+ opts.banner = "Generate points with uniform distribution on the sphere."
12
+ opts.on("-c", "--cartesian", "Cartesian coordinate."){|v|
13
+ options[:cartesian] = true
14
+ }
15
+ opts.on_tail("-h", "--help", "Show this message."){|v|
16
+ print opts.help
17
+ exit
18
+ }
19
+ opts.on_tail("-v", "--version", "Show version."){|v|
20
+ puts "v#{GSS::VERSION}"
21
+ exit
22
+ }
23
+ opts.parse!
24
+
25
+ r = ARGV.shift.to_f
26
+ n = ARGV.shift.to_i
27
+
28
+ gss = GSS::GSS.new
29
+ points = gss.generate(r, n)
30
+ points.each do |p|
31
+ if options[:cartesian]
32
+ coord = p.to_cartesian
33
+ print coord.to_csv
34
+ else
35
+ print [p.r, p.theta, p.phi].to_csv
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gss/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gss_generator"
8
+ spec.version = GSS::VERSION
9
+ spec.authors = ["takatoh"]
10
+ spec.email = ["takatoh.m@gmail.com"]
11
+
12
+ spec.summary = %q{Distribute many points with equal intervals on a sphere.}
13
+ spec.description = %q{Generate generalized spiral set that are the set of points with uniform distribution on a sphere.}
14
+ spec.homepage = "https://github.com/takatoh/gss_generator"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
@@ -0,0 +1,6 @@
1
+ require "gss/version"
2
+ require "gss/gss"
3
+
4
+ module GSS
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module GSS
5
+
6
+ class PolarPoint
7
+ attr_reader :r, :theta, :phi
8
+
9
+ def initialize(r, theta, phi)
10
+ @r = r
11
+ @theta = theta
12
+ @phi = phi
13
+ end
14
+
15
+ def to_cartesian
16
+ x = @r * Math.sin(@theta) * Math.cos(@phi)
17
+ y = @r * Math.sin(@theta) * Math.sin(@phi)
18
+ z = @r * Math.cos(@theta)
19
+ [x, y, z]
20
+ end
21
+ end # of class PolarPoint
22
+
23
+ end # of module GSS
@@ -0,0 +1,3 @@
1
+ module GSS
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gss_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - takatoh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Generate generalized spiral set that are the set of points with uniform
42
+ distribution on a sphere.
43
+ email:
44
+ - takatoh.m@gmail.com
45
+ executables:
46
+ - gss_gen
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - exe/gss_gen
58
+ - gss_generator.gemspec
59
+ - lib/gss.rb
60
+ - lib/gss/gss.rb
61
+ - lib/gss/polar_point.rb
62
+ - lib/gss/version.rb
63
+ homepage: https://github.com/takatoh/gss_generator
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.5.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Distribute many points with equal intervals on a sphere.
87
+ test_files: []