class SGS::Waypoint
Waypoint
, Attractor, and Repellor definitions
Attributes
Public Class Methods
Define a new Attractor or Repellor, based on certain parameters. The location is the centre of the waypoint. The normal is the compass angle of the start of the semicircle, and the radius is the size of the arc. You can specify an optional name for the waypoint and also indicate if we should be attracted or repelled by it.
# File lib/sgs/waypoint.rb, line 46 def initialize(location = nil, normal = 0.0, radius = 0.1, name = "", repellor = false) @location = location || Location.new @normal = normal @radius = radius @name = name @repellor = repellor @bearing = nil @distance = 0 end
Public Instance Methods
Is this an attractor?
# File lib/sgs/waypoint.rb, line 77 def attractor? @repellor == false end
Calculate the back-vector from the waypoint to the specified position. Calculate the adjusted distance between the position and the mark. Check to see if our back-bearing from the waypoint to our location is inside the chord of the waypoint, which is a semicircle commencing at the normal. If so, reduce the distance to the waypoint by the length of the chord. @distance is the adjusted distance to the location
# File lib/sgs/waypoint.rb, line 63 def compute_bearing(loc) @bearing = loc - @location @distance = @bearing.distance d = Bearing.new(@bearing.back_angle - @normal, @bearing.distance) # A chord angle of 0 gives a semicircle from 0 to 180 degrees. If our # approach angle is within range, then reduce our distance to the mark # by the chord distance (radius). @distance -= @radius if d.angle >= 0.0 and d.angle < Math::PI @distance = 0.0 if @distance < 0.0 @distance end
Is the waypoint in scope? In other words, is our angle inside the chord.
# File lib/sgs/waypoint.rb, line 89 def in_scope? puts "In-scope distance is %f..." % @distance @distance == 0.0 end
Convert the waypoint normal to/from degrees
# File lib/sgs/waypoint.rb, line 96 def normal_d Bearing.rtod @normal end
Convert the waypoint normal to/from degrees
# File lib/sgs/waypoint.rb, line 102 def normal_d=(val) @normal = Bearing.dtor val end
Is this a repellor?
# File lib/sgs/waypoint.rb, line 83 def repellor? @repellor == true end
Show the axis line for the waypoint (as a KML)
# File lib/sgs/waypoint.rb, line 126 def to_axis_kml puts "TO_AXIS_KML!" #::FIXME:: #c2 = @chord.clone #c2.angle += 1.5 * Math::PI #pos1 = @location.calculate(c2) #"#{@location.to_kml(',')} #{pos1.to_kml(',')}" end
Display a string for a KML file
# File lib/sgs/waypoint.rb, line 114 def to_kml puts "TO KML!" #p self #c2 = @chord.clone #c2.angle += Math::PI #pos1 = @location.calculate(@chord) #pos2 = @location.calculate(c2) #"#{pos1.to_kml(',')} #{pos2.to_kml(',')}" end
Pretty version of the waypoint.
# File lib/sgs/waypoint.rb, line 108 def to_s "'#{@name}' at #{@location} => #{normal_d}%#{@radius}" end