gstatsat 0.0.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 +7 -0
- data/lib/gstatsat.rb +67 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7fe440ab2ae9009f9ac0ac3151e7d315fd77b704
|
4
|
+
data.tar.gz: 3fe32a6cf71839a219a443f49caba9da695f5a61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1482f4eb9f656b7de67780376d5df8c2b1411bfb2491d0f621199ecc15498e00bd4e36b45695c0a052119d4f77966e103832eedbae3d0bff449414db053984a4
|
7
|
+
data.tar.gz: 7a5c6b170b23dd9b4356e1b0557cf98afecd7eaa0a7590dea3ab903bf339c2171c6d69122130e028de03fe04eec56b62b344251df99f8d92e9feadd9a5044cb2
|
data/lib/gstatsat.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Gstatsat
|
2
|
+
class Satellite
|
3
|
+
attr_accessor :longitude
|
4
|
+
def initialize(params = {})
|
5
|
+
validate(params)
|
6
|
+
@longitude = params.fetch(:longitude)
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate(params)
|
10
|
+
longitude = params.fetch(:longitude)
|
11
|
+
raise KeyError, 'longitude is not numeric' unless longitude.is_a? Numeric
|
12
|
+
raise KeyError, 'invalid longitude value' unless longitude >= -180 && longitude <= 180
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class BaseStation
|
17
|
+
attr_accessor :latitude, :longitude
|
18
|
+
def initialize(params = {})
|
19
|
+
validate(params)
|
20
|
+
@latitude = params.fetch(:latitude)
|
21
|
+
@longitude = params.fetch(:longitude)
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate(params)
|
25
|
+
longitude = params.fetch(:longitude)
|
26
|
+
latitude = params.fetch(:latitude)
|
27
|
+
raise KeyError, 'longitude is not numeric' unless longitude.is_a? Numeric
|
28
|
+
raise KeyError, 'latitude is not numeric' unless latitude.is_a? Numeric
|
29
|
+
raise KeyError, 'invalid longitude value' unless longitude >= -180 && longitude <= 180
|
30
|
+
raise KeyError, 'invalid latitude value' unless latitude >= -90 && latitude <= 90
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class SatelliteBearing
|
35
|
+
attr_accessor :azimuth, :elevation
|
36
|
+
def initialize(params = {})
|
37
|
+
@satellite = params.fetch(:satellite)
|
38
|
+
@base_station = params.fetch(:base_station)
|
39
|
+
calculate_bearing
|
40
|
+
end
|
41
|
+
|
42
|
+
def visible?
|
43
|
+
elevation > 0
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def calculate_bearing
|
48
|
+
earths_radius = 6371
|
49
|
+
satellite_height = 35786
|
50
|
+
azimuthal_angle_rads = to_radians(@base_station.longitude - @satellite.longitude)
|
51
|
+
base_station_latitude_rads = to_radians(@base_station.latitude)
|
52
|
+
sigma = earths_radius.to_f / ( earths_radius + satellite_height )
|
53
|
+
beta = Math.acos(Math.cos(base_station_latitude_rads) * Math.cos(azimuthal_angle_rads))
|
54
|
+
|
55
|
+
@elevation = to_degrees(Math.atan(( Math.cos(beta) - sigma) / Math.sin(beta))).round(1)
|
56
|
+
@azimuth = to_degrees(Math::PI + Math::atan(Math::tan(azimuthal_angle_rads)/Math::sin(base_station_latitude_rads))).round(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_radians(degrees)
|
60
|
+
degrees * Math::PI / 180
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_degrees(radians)
|
64
|
+
radians * 180 / Math::PI
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gstatsat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Greg Clarke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem for calculating bearings of geostationary satellites
|
14
|
+
email: greg@gho.st
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/gstatsat.rb
|
20
|
+
homepage: https://github.com/gregology/gstatsat
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Hola!
|
44
|
+
test_files: []
|