Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
better vector handling
- Loading branch information
1 parent
12ef60c
commit 4d9fdad
Showing
12 changed files
with
372 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,17 @@ | ||
module GeoMagic | ||
class Vector | ||
attr_accessor :p0, :p1 | ||
|
||
def initialize p0, p1 | ||
raise ArgumentError, "Vector must be initialized with a start end ending point, was: #{p0}, #{p1}" if ![p0, p1].are_points? | ||
@p0 = p0 | ||
@p1 = p1 | ||
end | ||
|
||
def self.create_at center, vector | ||
new center, center.move_vector(vector) | ||
end | ||
|
||
def length type = nil | ||
rad_dist = case type | ||
when nil | ||
GeoMagic::Distance.distance(p0, p1) | ||
when :latitude | ||
(p0.latitude - p1.latitude).abs | ||
when :longitude | ||
(p0.longitude - p1.longitude).abs | ||
else | ||
raise ArgumentError, "Bad argument for calculating lenght, valid args are: nil, :latitude or :longitude" | ||
class Vector | ||
# The vector from the origin O = (0,0) to the point A = (2,3) is simply written as (2,3). | ||
def apply_to arg | ||
def apply_to arg | ||
raise ArgumentError, "Argument must be a GeoMagic::Point or a GeoMagic::PointVector" if !arg.any_kind_of?(GeoMagic::Vector, GeoMagic::PointVector) | ||
case arg | ||
when GeoMagic::Point | ||
when GeoMagic::PointVector | ||
end | ||
end | ||
d = GeoMagic::Distance.new rad_dist, :radians | ||
d.lat_factor = p0.middle_point(p1).latitude_factor if type == :latitude | ||
d | ||
end | ||
|
||
def lat_distance | ||
length(:latitude).in_radians | ||
end | ||
|
||
def long_distance | ||
length(:longitude).in_radians | ||
end | ||
|
||
def vector_distance | ||
GeoMagic::Distance::Vector.new length(:latitude), length(:longitude), :lat_factor => lat_factor | ||
end | ||
|
||
def lat_factor | ||
p0.middle_point(p1).latitude_factor | ||
end | ||
|
||
# distance between points p0 and p1 that define the vector | ||
|
||
def distance unit = :radians | ||
dist = ::GeoMagic::Distance.calculate p0, p1 | ||
unit != :radians ? dist[unit] : dist | ||
end | ||
|
||
def distance_from center, unit = :meters | ||
point = center.move delta_latitude, delta_longitude | ||
dist = ::GeoMagic::Distance.calculate center, point | ||
unit != :radians ? dist[unit] : dist | ||
end | ||
|
||
def [] key | ||
case key | ||
when 0, :p0 | ||
p0 | ||
when 1, :p1 | ||
p1 | ||
else | ||
raise "Vector key must be either 0/1 or :p0/:p1" | ||
end | ||
end | ||
|
||
protected | ||
|
||
def connection_length | ||
Math.sqrt((delta_longitude + delta_latitude).abs) | ||
end | ||
|
||
def delta_longitude | ||
(p0.longitude - p1.longitude)**2 | ||
end | ||
|
||
def delta_latitude | ||
(p0.latitude - p1.latitude)**2 | ||
end | ||
end | ||
end | ||
|
||
require 'geo_magic/vector/point_vector' | ||
require 'geo_magic/vector/direction_vector' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module GeoMagic | ||
module Direction | ||
class Vector < GeoMagic::Vector | ||
attr_accessor :direction, :distance | ||
|
||
def initialize direction, distance | ||
raise ArgumentError, "Invalid direction: #{direction}" if !valid_directions.include?(direction) | ||
raise ArgumentError, "First argument must be a GeoMagic::Distance, was: #{distance}" if !distance.kind_of?(GeoMagic::Distance) | ||
@direction = direction | ||
@distance = distance | ||
end | ||
|
||
def self.valid_directions | ||
[:north, :south, :east, :west, :NW, :NE, :SW, :SE] | ||
end | ||
|
||
def to_point_vector | ||
GeoMagic::PointVector.from_origin calc_point | ||
end | ||
|
||
def apply_to arg | ||
raise ArgumentError, "Argument must be a GeoMagic::Point or a GeoMagic::PointVector" if !arg.any_kind_of?(GeoMagic::Vector, GeoMagic::PointVector) | ||
case arg | ||
when GeoMagic::Point | ||
when GeoMagic::PointVector | ||
end | ||
end | ||
|
||
protected | ||
|
||
def calc_point | ||
va = 45 | ||
c = distance | ||
a = c * 0.7071067770164218 # Math.sin(45 * Math.PI / 180); | ||
b = Math.sqrt((c * c) - (a * a)); | ||
|
||
lat, lng = case direction | ||
when :north | ||
[0, -distance] | ||
when :south | ||
[0, distance] | ||
when :west | ||
[-distance, 0] | ||
when :east | ||
[distance, 0] | ||
when :NW | ||
[a, b] | ||
when :SW | ||
[a, -b] | ||
when :NE | ||
[-a, b] | ||
when :SE | ||
[-a, -b] | ||
end | ||
GeoMagic::Point.new lat, lng | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.