trilateration 0.0.1 → 1.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 +4 -4
- data/.gitignore +9 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/README.md +39 -5
- data/Rakefile +12 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/lib/trilateration.rb +5 -1
- data/lib/trilateration/calculate.rb +27 -34
- data/lib/trilateration/version.rb +3 -0
- data/trilateration.gemspec +25 -15
- metadata +71 -10
- data/lib/trilateration/point.rb +0 -24
- data/tests/test_trilateration.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2e1830b0a0b59a44e16d87a46dfbe3e770ca8ff
|
4
|
+
data.tar.gz: b4ebf3a753c34beeb8ff6eaebfc0b7413fb5af64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 891ce789e1f09357ed92a36e161a60b91ef598f406c99adc79818335919f23095bc7f94795336ee4f445a0dc7683150c8153fb96dc514a8426ae521d38b6c72c
|
7
|
+
data.tar.gz: 3b311cca08a2296f9a055c458f7be806aa84547cfaf98d6bc829e13ed06efae46c56a1e8132eb7348a57924e5180d63758a21131517ade700e6e8e77c727d44b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,10 +1,44 @@
|
|
1
|
+
# Trilateration [](https://travis-ci.org/timgentry/trilateration)
|
2
|
+
|
1
3
|
Trilateration calculates the position of an unknown point, using the distance from three known points to it.
|
2
4
|
|
3
|
-
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'trilateration'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install trilateration
|
4
20
|
|
5
|
-
|
6
|
-
|
7
|
-
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
p1 = Vector[1, 2, 0]
|
25
|
+
p2 = Vector[8, 6, 0]
|
26
|
+
p3 = Vector[1, 6, 0]
|
8
27
|
tri = Trilateration::Calculate.new(p1, p2, p3)
|
9
28
|
|
10
|
-
output = tri.calculate_from_distances(4.02305854, 4.
|
29
|
+
output = tri.calculate_from_distances(4.02305854, 4.29941857, 3.87104637)
|
30
|
+
```
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/timgentry/trilateration/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'trilateration'
|
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
|
+
require 'pry'
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
data/lib/trilateration.rb
CHANGED
@@ -1,62 +1,55 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
|
1
3
|
module Trilateration
|
2
4
|
class Calculate
|
3
5
|
attr_accessor :point1, :point2, :point3, :rel_point1, :rel_point2, :rel_point3
|
4
6
|
|
5
7
|
# where point1 is our origin, and p2 and p3 are two other
|
6
8
|
# sensors in which we know the relative positions
|
7
|
-
def initialize
|
9
|
+
def initialize(p1, p2, p3)
|
8
10
|
@point1 = p1
|
9
11
|
@point2 = p2
|
10
12
|
@point3 = p3
|
11
13
|
|
12
14
|
# adjust all the points so that they are relative to p1
|
13
|
-
@rel_point1 =
|
14
|
-
@rel_point2 =
|
15
|
-
@rel_point3 =
|
15
|
+
@rel_point1 = Vector[0, 0, 0]
|
16
|
+
@rel_point2 = @point2 - @point1
|
17
|
+
@rel_point3 = @point3 - @point1
|
16
18
|
end
|
17
19
|
|
18
|
-
# Trilaterating an X,Y coordinate of an object based on its distance
|
20
|
+
# Trilaterating an X,Y coordinate of an object based on its distance
|
19
21
|
# from three sensor points which are at known coordinate positions
|
20
22
|
# input: target point relative to the first sensor
|
21
|
-
def calculate_from_distances
|
22
|
-
|
23
|
+
def calculate_from_distances(dist1, dist2, dist3)
|
24
|
+
# From Wikipedia: https://en.wikipedia.org/wiki/Trilateration
|
25
|
+
ex = @rel_point2 / @rel_point2.norm
|
26
|
+
i = ex.dot(@rel_point3)
|
27
|
+
ey = (@rel_point3 - (i * ex)) / (@rel_point3 - (i * ex)).norm
|
28
|
+
ez = ex.cross(ey)
|
29
|
+
d = @rel_point2.norm
|
30
|
+
j = ey.dot(@rel_point3)
|
23
31
|
|
24
|
-
|
25
|
-
|
32
|
+
x = (dist1**2 - dist2**2 + d**2) / (2 * d)
|
33
|
+
y = ((dist1**2 - dist3**2 + i**2 + j**2) / (2 * j)) - ((i / j) * x)
|
26
34
|
|
27
|
-
|
35
|
+
z = Math.sqrt((dist1**2 - x**2 - y**2).abs)
|
28
36
|
|
29
|
-
|
30
|
-
|
31
|
-
Point.new(x, y, z)
|
37
|
+
@point1 + (x * ex) + (y * ey) + (z * ez)
|
32
38
|
end
|
33
39
|
|
34
40
|
# used similarly as calculate_from_distances, except this is a test method
|
35
41
|
# input: a target point whose coordinates from @point1 are already known,
|
36
42
|
# in order to test the trilateration algorithm quickly
|
37
|
-
def calculate_from_test_point
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
dist3 = calculate_dist3(rel_target_point)
|
42
|
-
|
43
|
-
calculate_from_distances(dist1, dist2, dist3)
|
44
|
-
end
|
45
|
-
|
46
|
-
def get_relative_point relative_point, origin_point
|
47
|
-
Point.new(relative_point.x - origin_point.x, relative_point.y - origin_point.y, relative_point.z - origin_point.z)
|
48
|
-
end
|
49
|
-
|
50
|
-
def calculate_dist1 target_point
|
51
|
-
((target_point.x ** 2) + (target_point.y ** 2) + (target_point.z ** 2)) ** 0.5
|
52
|
-
end
|
43
|
+
def calculate_from_test_point(target_point)
|
44
|
+
dist1 = calculate_distance(target_point, @point1)
|
45
|
+
dist2 = calculate_distance(target_point, @point2)
|
46
|
+
dist3 = calculate_distance(target_point, @point3)
|
53
47
|
|
54
|
-
|
55
|
-
(((target_point.x - @rel_point2.x) ** 2) + (target_point.y ** 2) + (target_point.z ** 2)) ** 0.5
|
48
|
+
calculate_from_distances(dist1, dist2, dist3)
|
56
49
|
end
|
57
50
|
|
58
|
-
def
|
59
|
-
(
|
51
|
+
def calculate_distance(target_point, origin_point)
|
52
|
+
(target_point - origin_point).r
|
60
53
|
end
|
61
54
|
end
|
62
|
-
end
|
55
|
+
end
|
data/trilateration.gemspec
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trilateration/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'trilateration'
|
8
|
+
spec.version = Trilateration::VERSION
|
9
|
+
spec.authors = ['Patrick Read', 'Tim Gentry']
|
10
|
+
|
11
|
+
spec.summary = %q(Performs a trilateration operation in order to find an unknown point in a Cartesian coordinate system.)
|
12
|
+
spec.description = %q(Trilateration calculates the position of an unknown point, using the distance from three known points to it.)
|
13
|
+
spec.homepage = 'https://github.com/patrickread/trilateration'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'minitest'
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
end
|
metadata
CHANGED
@@ -1,28 +1,90 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trilateration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Read
|
8
|
+
- Tim Gentry
|
8
9
|
autorequire:
|
9
|
-
bindir:
|
10
|
+
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
12
|
+
date: 2017-06-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.9'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.9'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: pry
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
13
70
|
description: Trilateration calculates the position of an unknown point, using the
|
14
71
|
distance from three known points to it.
|
15
|
-
email:
|
72
|
+
email:
|
16
73
|
executables: []
|
17
74
|
extensions: []
|
18
75
|
extra_rdoc_files: []
|
19
76
|
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
20
80
|
- LICENSE
|
21
81
|
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
22
85
|
- lib/trilateration.rb
|
23
86
|
- lib/trilateration/calculate.rb
|
24
|
-
- lib/trilateration/
|
25
|
-
- tests/test_trilateration.rb
|
87
|
+
- lib/trilateration/version.rb
|
26
88
|
- trilateration.gemspec
|
27
89
|
homepage: https://github.com/patrickread/trilateration
|
28
90
|
licenses:
|
@@ -44,10 +106,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
106
|
version: '0'
|
45
107
|
requirements: []
|
46
108
|
rubyforge_project:
|
47
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.8
|
48
110
|
signing_key:
|
49
111
|
specification_version: 4
|
50
112
|
summary: Performs a trilateration operation in order to find an unknown point in a
|
51
113
|
Cartesian coordinate system.
|
52
|
-
test_files:
|
53
|
-
- tests/test_trilateration.rb
|
114
|
+
test_files: []
|
data/lib/trilateration/point.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Trilateration
|
2
|
-
class Point
|
3
|
-
attr_accessor :x, :y, :z
|
4
|
-
|
5
|
-
# Third dimension is optional
|
6
|
-
def initialize pointX, pointY, pointZ=0
|
7
|
-
@x = pointX
|
8
|
-
@y = pointY
|
9
|
-
@z = pointZ
|
10
|
-
end
|
11
|
-
|
12
|
-
def x_rounded
|
13
|
-
@x.round(3)
|
14
|
-
end
|
15
|
-
|
16
|
-
def y_rounded
|
17
|
-
@y.round(3)
|
18
|
-
end
|
19
|
-
|
20
|
-
def z_rounded
|
21
|
-
@z.round(3)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/tests/test_trilateration.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "minitest/autorun"
|
4
|
-
require_relative '../lib/trilateration.rb'
|
5
|
-
require_relative '../lib/point.rb'
|
6
|
-
|
7
|
-
class TrilaterationTest < Minitest::Test
|
8
|
-
|
9
|
-
def test_trilateration
|
10
|
-
p1 = Point.new(1,2)
|
11
|
-
p2 = Point.new(8,6)
|
12
|
-
p3 = Point.new(1,6)
|
13
|
-
tri = Trilateration.new(p1, p2, p3)
|
14
|
-
|
15
|
-
test_output = tri.calculate_from_test_point(Point.new(4.25, 4.15, 1))
|
16
|
-
output = tri.calculate_from_distances(4.02305854, 4.43677811, 3.87104637)
|
17
|
-
|
18
|
-
assert_equal(test_output.x_rounded, output.x_rounded, "X Coordinate is not correct")
|
19
|
-
assert_equal(test_output.y_rounded, output.y_rounded, "Y Coordinate is not correct")
|
20
|
-
|
21
|
-
if (!test_output.z.is_a?(Complex))
|
22
|
-
refute_kind_of(Complex, output.z, "Z Coordinate shouldn't be a Complex")
|
23
|
-
assert_equal(test_output.z_rounded, output.z_rounded, "Z Coordinate is not correct")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|