class SGS::Waypoint

Waypoint, Attractor, and Repellor definitions

Attributes

bearing[RW]
distance[R]
location[RW]
name[RW]
normal[RW]
radius[RW]
repellor[RW]

Public Class Methods

new(location = nil, normal = 0.0, radius = 0.1, name = "", repellor = false) click to toggle source

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

attractor?() click to toggle source

Is this an attractor?

# File lib/sgs/waypoint.rb, line 77
def attractor?
  @repellor == false
end
compute_bearing(loc) click to toggle source

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
in_scope?() click to toggle source

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
normal_d() click to toggle source

Convert the waypoint normal to/from degrees

# File lib/sgs/waypoint.rb, line 96
def normal_d
  Bearing.rtod @normal
end
normal_d=(val) click to toggle source

Convert the waypoint normal to/from degrees

# File lib/sgs/waypoint.rb, line 102
def normal_d=(val)
  @normal = Bearing.dtor val
end
repellor?() click to toggle source

Is this a repellor?

# File lib/sgs/waypoint.rb, line 83
def repellor?
  @repellor == true
end
to_axis_kml() click to toggle source

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
to_kml() click to toggle source

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
to_s() click to toggle source

Pretty version of the waypoint.

# File lib/sgs/waypoint.rb, line 108
def to_s
  "'#{@name}' at #{@location} => #{normal_d}%#{@radius}"
end