Пример #1
0
OZBoundary
AnnularSectorZone::GetBoundary() const
{
  OZBoundary boundary;

  const unsigned steps = 20;
  const Angle delta = Angle::FullCircle() / steps;
  const Angle start = GetStartRadial().AsBearing();
  Angle end = GetEndRadial().AsBearing();
  if (end <= start + Angle::FullCircle() / 512)
    end += Angle::FullCircle();

  const GeoPoint inner_start =
    GeoVector(GetInnerRadius(), GetStartRadial()).EndPoint(GetReference());
  const GeoPoint inner_end =
    GeoVector(GetInnerRadius(), GetEndRadial()).EndPoint(GetReference());

  GeoVector inner_vector(GetInnerRadius(), start + delta);
  for (; inner_vector.bearing < end; inner_vector.bearing += delta)
    boundary.push_front(inner_vector.EndPoint(GetReference()));

  boundary.push_front(inner_end);
  boundary.push_front(inner_start);

  GeoVector vector(GetRadius(), start + delta);
  for (; vector.bearing < end; vector.bearing += delta)
    boundary.push_front(vector.EndPoint(GetReference()));

  boundary.push_front(GetSectorEnd());
  boundary.push_front(GetSectorStart());

  return boundary;
}
Пример #2
0
GeoPoint
AircraftSim::endpoint(const Angle &heading, const fixed timestep) const
{
  GeoPoint ref = GeoVector(state.true_airspeed*timestep, heading).end_point(state.location);
  return GeoVector(state.wind.norm*timestep,
                   state.wind.bearing+ Angle::degrees(fixed_180)).end_point(ref);
}
Пример #3
0
GeoVector 
TaskLeg::leg_vector_remaining(const GeoPoint &ref) const
{
  switch (destination.getActiveState()) {
  case OrderedTaskPoint::AFTER_ACTIVE:
    if (!origin()) {
      return GeoVector(fixed_zero);
    }
    // this leg totally included
    return memo_remaining.calc(origin()->get_location_remaining(), 
                               destination.get_location_remaining());
    break;
  case OrderedTaskPoint::CURRENT_ACTIVE:
    if (!origin()) {
      return GeoVector(fixed_zero, 
                       ref.bearing(destination.get_location_remaining()));
    }
    // this leg partially included
    return memo_remaining.calc(ref, 
                               destination.get_location_remaining());
    break;
  case OrderedTaskPoint::BEFORE_ACTIVE:
    // this leg not included
  default:
    assert(1); // error!
    return GeoVector(fixed_zero);
  };
}
Пример #4
0
const FlatBoundingBox 
AirspaceCircle::get_bounding_box(const TaskProjection& task_projection) 
{
  static const Angle a225 = Angle::degrees(fixed(225));
  static const Angle a135 = Angle::degrees(fixed(135));
  static const Angle a045 = Angle::degrees(fixed(045));
  static const Angle a315 = Angle::degrees(fixed(315));

  const fixed eradius = m_radius * fixed(1.42);
  const GeoPoint ll = GeoVector(eradius, a225).end_point(m_center);
  const GeoPoint lr = GeoVector(eradius, a135).end_point(m_center);
  const GeoPoint ur = GeoVector(eradius, a045).end_point(m_center);
  const GeoPoint ul = GeoVector(eradius, a315).end_point(m_center);

  FlatGeoPoint fll = task_projection.project(ll);
  FlatGeoPoint flr = task_projection.project(lr);
  FlatGeoPoint ful = task_projection.project(ul);
  FlatGeoPoint fur = task_projection.project(ur);

  // note +/- 1 to ensure rounding keeps bb valid 

  return FlatBoundingBox(FlatGeoPoint(min(fll.Longitude, ful.Longitude) - 1,
                                      min(fll.Latitude, flr.Latitude) - 1),
                         FlatGeoPoint(max(flr.Longitude, fur.Longitude) + 1,
                                      max(ful.Latitude, fur.Latitude) + 1));
}
Пример #5
0
GeoVector 
AbortTask::GetHomeVector(const AircraftState &state) const
{
  const Waypoint *home_waypoint = GetHome();
  if (home_waypoint)
    return GeoVector(state.location, home_waypoint->location);

  return GeoVector(fixed_zero);
}
Пример #6
0
GeoPoint 
BGAEnhancedOptionZone::get_boundary_parametric(fixed t) const
{ 
  const Angle half = getStartRadial().HalfAngle(getEndRadial());
  const Angle angle = (Angle::radians(t*fixed_two_pi)+half).as_bearing();
  if (angleInSector(angle)) {
    return GeoVector(Radius, angle).end_point(get_location());
  } else {
    return GeoVector(fixed(500), angle).end_point(get_location());
  }
}
Пример #7
0
  GeoVector 
  GetVector(fixed time) const
  {
    assert(Ready());

    if (!positive(p[2].t-p[1].t)) {
      return GeoVector(fixed_zero, Angle::zero());
    }

    const Record r0 = Interpolate(time - fixed(0.05));
    const Record r1 = Interpolate(time + fixed(0.05));
    return GeoVector(p[1].loc.distance(p[2].loc)/
                     (p[2].t-p[1].t), r0.loc.bearing(r1.loc));
  }
Пример #8
0
GeoPoint
AnnularSectorZone::GetBoundaryParametric(fixed t) const
{
  const Angle sweep = (EndRadial-StartRadial).as_bearing();
  const fixed c0 = sweep.value_radians()*InnerRadius;
  const fixed l = Radius-InnerRadius;
  const fixed c1 = sweep.value_radians()*Radius;
  const fixed tt = t*(c0+c1+2*l);
  Angle a;
  fixed d;
  if (tt< c0) {
    d = InnerRadius;
    a = Angle::radians((tt/c0)*sweep.value_radians())+StartRadial;
  } else if (positive(l) && (tt<c0+l)) {
    d = (tt-c0)/l*(Radius-InnerRadius)+InnerRadius;
    a = EndRadial;
  } else if (tt<c0+l+c1) {
    d = Radius;
    a = EndRadial-Angle::radians(((tt-c0-l)/c1)*sweep.value_radians());
  } else if (positive(l)) {
    d = (tt-c0-l-c1)/l*(InnerRadius-Radius)+Radius;
    a = StartRadial;
  } else {
    d = InnerRadius;
    a = StartRadial;
  }
  return GeoVector(d, a).end_point(get_location());
}
GeoPoint 
KeyholeZone::get_boundary_parametric(fixed t) const
{ 
  const fixed sweep = (getEndRadial() - getStartRadial()).as_bearing().value_radians();
  const fixed small_sweep = fixed_two_pi-sweep;
  const fixed SmallRadius = fixed(500);
  const fixed c1 = sweep*Radius; // length of sector element
  const fixed c2 = small_sweep*SmallRadius*fixed(5); // length of cylinder element
  const fixed l = (Radius-SmallRadius)*fixed(0.2); // length of straight elements
  const fixed tt = t*(c1+l+l+c2); // total distance
  Angle a;
  fixed d;
  if (tt<l) { // first straight element
    d = (tt/l)*(Radius-SmallRadius)+SmallRadius;
    a = getStartRadial();
  } else if (tt<l+c1) { // sector element
    d = Radius;
    a = getStartRadial() + Angle::radians((tt-l)/c1*sweep);
  } else if (tt<l+l+c1) { // second straight element
    d = (fixed_one-(tt-l-c1)/l)*(Radius-SmallRadius)+SmallRadius;
    a = getEndRadial();
  } else { // cylinder element
    d = SmallRadius;
    a = getEndRadial() + Angle::radians((tt-l-l-c1)/c2*small_sweep);
  }
  return GeoVector(d, a).end_point(get_location());
}
Пример #10
0
static void
OnPaintListItem(Canvas &canvas, const PixelRect rc, unsigned i)
{
  if (waypoint_select_info.empty()) {
    assert(i == 0);

    const UPixelScalar line_height = rc.bottom - rc.top;
    const Font &name_font =
      *UIGlobals::GetDialogLook().list.font;
    canvas.SetTextColor(COLOR_BLACK);
    canvas.Select(name_font);
    canvas.text(rc.left + line_height + Layout::FastScale(2),
                rc.top + line_height / 2 - name_font.GetHeight() / 2,
                filter_data.IsDefined() || way_points.IsEmpty() ?
                _("No Match!") : _("Choose a filter or click here"));
    return;
  }

  assert(i < waypoint_select_info.size());

  const struct WaypointSelectInfo &info = waypoint_select_info[i];

  WaypointListRenderer::Draw(canvas, rc, *info.waypoint,
                             GeoVector(info.distance, info.direction),
                             UIGlobals::GetDialogLook(),
                             UIGlobals::GetMapLook().waypoint,
                             CommonInterface::GetMapSettings().waypoint);
}
Пример #11
0
  GeoVector 
  GetVector(fixed _time) const
  {
    assert(Ready());

    if (!positive(p[2].time-p[1].time))
      return GeoVector(fixed(0), Angle::Zero());

    const Record r0 = Interpolate(_time - fixed(0.05));
    const Record r1 = Interpolate(_time + fixed(0.05));

    fixed speed = p[1].location.Distance(p[2].location) / (p[2].time - p[1].time);
    Angle bearing = r0.location.Bearing(r1.location);

    return GeoVector(speed, bearing);
  }
Пример #12
0
  GeoVector 
  GetVector(fixed time) const
  {
    if (!Ready())
      return fixed_zero;

    if (!positive(p[2].t-p[1].t)) {
      return GeoVector(fixed_zero, Angle::native(fixed_zero));
    }
    fixed alt, palt;
    GeoPoint p0, p1;
    Interpolate(time-fixed(0.05), p0, alt, palt);
    Interpolate(time+fixed(0.05), p1, alt, palt);
    return GeoVector(p[1].loc.distance(p[2].loc)/
                     (p[2].t-p[1].t), p0.bearing(p1));
  }
Пример #13
0
GeoPoint
AnnularSectorZone::GetBoundaryParametric(fixed t) const
{
  const Angle sweep = (GetEndRadial() - GetStartRadial()).AsBearing();
  const fixed c0 = sweep.Radians() * inner_radius;
  const fixed l = GetRadius() - inner_radius;
  const fixed c1 = sweep.Radians() * GetRadius();
  const fixed tt = t * (c0 + c1 + 2 * l);
  Angle a;
  fixed d;
  if (tt < c0) {
    d = inner_radius;
    a = Angle::Radians((tt / c0) * sweep.Radians()) + GetStartRadial();
  } else if (positive(l) && (tt < c0 + l)) {
    d = (tt - c0) / l * (GetRadius() - inner_radius) + inner_radius;
    a = GetEndRadial();
  } else if (tt < c0 + l + c1) {
    d = GetRadius();
    a = GetEndRadial()
        - Angle::Radians(((tt - c0 - l) / c1) * sweep.Radians());
  } else if (positive(l)) {
    d = (tt - c0 - l - c1) / l * (inner_radius - GetRadius()) + GetRadius();
    a = GetStartRadial();
  } else {
    d = inner_radius;
    a = GetStartRadial();
  }
  return GeoVector(d, a).EndPoint(GetReference());
}
Пример #14
0
void
TrafficListWidget::UpdateList()
{
  assert(filter_widget != nullptr);

  items.clear();
  last_update.Clear();

  const TCHAR *callsign = filter_widget->GetValueString(CALLSIGN);
  if (!StringIsEmpty(callsign)) {
    FlarmId ids[30];
    unsigned count = FlarmDetails::FindIdsByCallSign(callsign, ids, 30);

    for (unsigned i = 0; i < count; ++i)
      AddItem(ids[i]);
  } else {
    /* if no filter was set, show a list of current traffic and known
       traffic */

    /* add live FLARM traffic */
    for (const auto &i : CommonInterface::Basic().flarm.traffic.list) {
      AddItem(i.id);
    }

    /* add FLARM peers that have a user-defined color */
    for (const auto &i : traffic_databases->flarm_colors) {
      Item &item = AddItem(i.first);
      item.color = i.second;
    }

    /* add FLARM peers that have a user-defined name */
    for (const auto &i : traffic_databases->flarm_names) {
      AddItem(i.id);
    }

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
    /* show SkyLines traffic unless this is a FLARM traffic picker
       dialog (from dlgTeamCode) */
    if (action_listener == nullptr) {
      const auto &data = tracking->GetSkyLinesData();
      const ScopeLock protect(data.mutex);
      for (const auto &i : data.traffic) {
        items.emplace_back(i.first, i.second.location);
        Item &item = items.back();

        if (i.second.location.IsValid() &&
            CommonInterface::Basic().location_available)
          item.vector = GeoVector(CommonInterface::Basic().location,
                                  i.second.location);
      }
    }
#endif
  }

  GetList().SetLength(items.size());

  UpdateVolatile();
  UpdateButtons();
}
Пример #15
0
const GeoVector &
WaypointListItem::GetVector(const GeoPoint &location) const
{
  if (!vec.IsValid())
    vec = GeoVector(location, waypoint->location);

  return vec;
}
Пример #16
0
GeoQuaternion::GeoQuaternion( const GeoVector& rotation_axis, const float degrees )
{
	GeoVector normalized_rotation_axis = GeoVector(rotation_axis).Normalize();
	const float radians = GeoConvertToRadians( degrees );
    x = sin( radians / 2.0f ) * normalized_rotation_axis.x;
    y = sin( radians / 2.0f ) * normalized_rotation_axis.y;
    z = sin( radians / 2.0f ) * normalized_rotation_axis.z;
    w = cos( radians / 2.0f );
}
Пример #17
0
GlideResult
RoutePolar::SolveTask(const GlidePolar& glide_polar,
                       const SpeedVector& wind,
                       const Angle theta, const bool glide) const
{
  fixed altitude = glide? fixed(1.0e5): fixed_zero;
  GlideState task(GeoVector(fixed(1.0), theta), fixed_zero, altitude, wind);
  return MacCready::Solve(glide_polar, task);
}
Пример #18
0
GeoVector
TaskLeg::GetNominalLegVector() const
{
  if (!GetOrigin()) {
    return GeoVector(fixed(0));
  } else {
    return memo_nominal.calc(GetOrigin()->GetLocation(),
                             destination.GetLocation());
  }
}
Пример #19
0
GeoVector 
TaskLeg::GetPlannedVector() const
{
  if (!GetOrigin()) {
    return GeoVector(fixed(0));
  } else {
    return memo_planned.calc(GetOrigin()->GetLocationRemaining(),
                             destination.GetLocationRemaining());
  }
}
Пример #20
0
GeoVector 
TaskLeg::leg_vector_planned() const
{
  if (!origin()) {
    return GeoVector(fixed_zero);
  } else {
    return memo_planned.calc(origin()->get_location_remaining(), 
                             destination.get_location_remaining());
  }
}
Пример #21
0
const GeoVector &
AirspaceSelectInfo::GetVector(const GeoPoint &location,
                              const FlatProjection &projection) const
{
  if (!vec.IsValid()) {
    const auto closest_loc = airspace->ClosestPoint(location, projection);
    vec = GeoVector(location, closest_loc);
  }

  return vec;
}
Пример #22
0
GeoVector 
AbortTask::get_vector_home(const AIRCRAFT_STATE &state) const
{
  const Waypoint* home_waypoint = waypoints.find_home();
  if (home_waypoint) {
    return GeoVector(state.Location, home_waypoint->Location);
  } else {
    GeoVector null_vector(fixed_zero);
    return null_vector;
  }
}
Пример #23
0
GeoVector 
GeoVectorMemento::calc(const GeoPoint& _origin,
                       const GeoPoint& _destination) const
{
  if (negative(value.Distance) || (_origin != origin)||(_destination != destination)) {
    origin = _origin;
    destination = _destination;
    value = GeoVector(origin,destination);
  };
  return value;
}
Пример #24
0
AircraftState
AircraftStateFilter::GetPredictedState(const double in_time) const
{
  AircraftState state_next = last_state;
  state_next.ground_speed = GetSpeed();
  state_next.vario = GetClimbRate();
  state_next.altitude = last_state.altitude + state_next.vario * in_time;
  state_next.location = GeoVector(state_next.ground_speed * in_time,
                                  GetBearing()).EndPoint(last_state.location);
  return state_next;
}
Пример #25
0
GeoPoint
TaskAutoPilot::get_start_location(const TaskAccessor& task, bool previous)
{
    if (!previous && (task.is_ordered())) {
        // set start location to 200 meters directly behind start
        // (otherwise start may fail to trigger)
        Angle brg = w[0].Bearing(w[1]);
        return GeoVector(fixed(200), brg).EndPoint(w[1]);
    } else {
        return w[0];
    }
}
Пример #26
0
std::vector<GeoVector>
ReferenceElement::refCoor() const
{
    std::vector<GeoVector> coordinates (M_nbDof, GeoVector (3) );
    for (UInt i (0); i < M_nbDof; ++i)
    {
        coordinates[i][0] = M_refCoor[3 * i];
        coordinates[i][1] = M_refCoor[3 * i + 1];
        coordinates[i][2] = M_refCoor[3 * i + 2];
    }
    return coordinates;
}
Пример #27
0
GlideResult
RoutePolar::SolveTask(const GlideSettings &settings,
                      const GlidePolar& glide_polar,
                       const SpeedVector& wind,
                       const Angle theta, const bool glide) const
{
  const MacCready mac_cready(settings, glide_polar);
  GlideState task(GeoVector(fixed(1), theta), fixed(0), fixed(0), wind);
  return glide
    ? mac_cready.SolveStraight(task)
    : mac_cready.Solve(task);
}
Пример #28
0
static void
TestGetNearest(const Waypoints &waypoints, const GeoPoint &center)
{
  WaypointPtr waypoint;
  GeoPoint near = GeoVector(fixed(250), Angle::Degrees(15)).EndPoint(center);
  GeoPoint far = GeoVector(fixed(750), Angle::Degrees(15)).EndPoint(center);
  GeoPoint further = GeoVector(fixed(4200), Angle::Degrees(48)).EndPoint(center);

  ok1((waypoint = waypoints.GetNearest(center, fixed(1))) != NULL);
  ok1(waypoint->original_id == 0);

  ok1((waypoint = waypoints.GetNearest(center, fixed(10000))) != NULL);
  ok1(waypoint->original_id == 0);

  ok1((waypoint = waypoints.GetNearest(near, fixed(1))) == NULL);

  ok1((waypoint = waypoints.GetNearest(near, fixed(10000))) != NULL);
  ok1(waypoint->original_id == 0);

  ok1((waypoint = waypoints.GetNearest(far, fixed(1))) == NULL);

  ok1((waypoint = waypoints.GetNearest(far, fixed(10000))) != NULL);
  ok1(waypoint->original_id == 1);

  ok1((waypoint = waypoints.GetNearestLandable(center, fixed(1))) != NULL);
  ok1(waypoint->original_id == 0);

  ok1((waypoint = waypoints.GetNearestLandable(center, fixed(10000))) != NULL);
  ok1(waypoint->original_id == 0);

  ok1((waypoint = waypoints.GetNearestLandable(further, fixed(1))) == NULL);

  ok1((waypoint = waypoints.GetNearestLandable(further, fixed(10000))) != NULL);
  ok1(waypoint->original_id == 3);

  ok1((waypoint = waypoints.GetNearestIf(center, fixed(1), OriginalIDAbove5)) == NULL);

  ok1((waypoint = waypoints.GetNearestIf(center, fixed(10000), OriginalIDAbove5)) != NULL);
  ok1(waypoint->original_id == 6);
}
Пример #29
0
GeoVector
TaskLeg::leg_vector_travelled(const GeoPoint &ref) const
{
  switch (destination.getActiveState()) {
  case OrderedTaskPoint::BEFORE_ACTIVE:
    if (!origin()) {
      return GeoVector(fixed_zero);
    }
    // this leg totally included
    return memo_travelled.calc(origin()->get_location_travelled(), 
                               destination.get_location_travelled());
    break;
  case OrderedTaskPoint::CURRENT_ACTIVE:
    // this leg partially included
    if (!origin()) {
      return GeoVector(fixed_zero, 
                       ref.bearing(destination.get_location_remaining()));
    }
    if (destination.has_entered()) {
      return memo_travelled.calc(origin()->get_location_travelled(), 
                                 destination.get_location_travelled());
    } else {
      return memo_travelled.calc(origin()->get_location_travelled(), 
                                 ref);
    }
    break;
  case OrderedTaskPoint::AFTER_ACTIVE:
    if (!origin()) {
      return GeoVector(fixed_zero);
    }
    // this leg may be partially included
    if (origin()->has_entered()) {
      return memo_travelled.calc(origin()->get_location_travelled(), 
                                 ref);
    }
  default:
    return GeoVector(fixed_zero);
  };
}
Пример #30
0
GeoVector 
GeoVectorMemento::calc(const GeoPoint& _origin,
                       const GeoPoint& _destination) const
{
  if (!value.IsValid() ||
      _origin != origin ||
      _destination != destination) {
    origin = _origin;
    destination = _destination;
    value = GeoVector(origin, destination);
  }

  return value;
}