Example #1
0
int main(int argc, char **argv)
{
#ifdef USE_WGS84
  plan_tests(9 + 36);
#else
  plan_tests(9 + 36 + 18);
#endif

  const GeoPoint a(Angle::Degrees(7.7061111111111114),
                   Angle::Degrees(51.051944444444445));
  const GeoPoint b(Angle::Degrees(7.599444444444444),
                   Angle::Degrees(51.099444444444444));
  const GeoPoint c(Angle::Degrees(4.599444444444444),
                   Angle::Degrees(47.099444444444444));

  fixed distance = Distance(a, b);
#ifdef USE_WGS84
  ok1(distance > fixed(9150) && distance < fixed(9160));
#else
  ok1(distance > fixed(9130) && distance < fixed(9140));
#endif

  Angle bearing = Bearing(a, b);
  ok1(bearing.Degrees() > fixed(304));
  ok1(bearing.Degrees() < fixed(306));

  bearing = Bearing(b, a);
  ok1(bearing.Degrees() > fixed(124));
  ok1(bearing.Degrees() < fixed(126));

  distance = ProjectedDistance(a, b, a);
  ok1(is_zero(distance));
  distance = ProjectedDistance(a, b, b);

#ifdef USE_WGS84
  ok1(distance > fixed(9150) && distance < fixed(9180));
#else
  ok1(distance > fixed(9120) && distance < fixed(9140));
#endif

  const GeoPoint middle(a.longitude.Fraction(b.longitude, fixed(0.5)),
                        a.latitude.Fraction(b.latitude, fixed(0.5)));
  distance = ProjectedDistance(a, b, middle);
#ifdef USE_WGS84
  ok1(distance > fixed(9150/2) && distance < fixed(9180/2));
#else
  ok1(distance > fixed(9100/2) && distance < fixed(9140/2));
#endif

  fixed big_distance = Distance(a, c);
  ok1(big_distance > fixed(494000) && big_distance < fixed(495000));

  TestLinearDistance();

  return exit_status();
}
Example #2
0
void Stroker::Round(const Pointf& p, const Pointf& v1, const Pointf& v2, double r)
{
	double tolerance = 0.3;
	double a1 = Bearing(v1);
	double a2 = Bearing(v2);
	if(a1 < a2)
		a1 += 2 * M_PI;
	while(a1 > a2) {
		PutLine(Polar(p, r, a1));
		a1 -= fid;
	}
}
Example #3
0
NAMESPACE_UPP

void BufferPainter::BeginOnPathOp(double q, bool abs)
{
	if(onpath.GetCount() == 0)
		RenderPath(ONPATH, NULL, RGBAZero());
	Begin();
	if(pathlen > 0) {
		if(!abs)
			q *= pathlen;
		Pointf pos(0, 0);
		for(int i = 0; i < onpath.GetCount(); i++) {
			PathLine& l = onpath[i];
			if(l.len > 0 && (l.len > q || q >= 1.0 && i == onpath.GetCount() - 1)) {
				Pointf v = l.p - pos;
				Translate(q / l.len * v + pos);
				Rotate(Bearing(v));
				break;
			}
			q -= l.len;
			pos = l.p;
		}
	}
	attrstack.Top().onpath = true;
	onpathstack.Add() = onpath;
	pathlenstack.Add(pathlen);
	onpath.Clear();
	pathlen = 0;
}
Example #4
0
Xform2D GetLineSzXform(const Pointf& p1, const Pointf& p2, const Sizef& sz)
{
	Xform2D m = Xform2D::Scale(Distance(p1, p2) / sz.cx);
	m = m * Xform2D::Rotation(Bearing(p2 - p1));
	m = m * Xform2D::Translation(p1.x, p1.y);
	return m;
}
Example #5
0
int main(int argc, char **argv)
{
    plan_tests(9 + 36 + 18);

    const GeoPoint a(Angle::degrees(fixed(7.7061111111111114)),
                     Angle::degrees(fixed(51.051944444444445)));
    const GeoPoint b(Angle::degrees(fixed(7.599444444444444)),
                     Angle::degrees(fixed(51.099444444444444)));
    const GeoPoint c(Angle::degrees(fixed(4.599444444444444)),
                     Angle::degrees(fixed(47.099444444444444)));

    fixed distance = Distance(a, b);
    ok1(distance > fixed(9130) && distance < fixed(9140));

    Angle bearing = Bearing(a, b);
    ok1(bearing.value_degrees() > fixed(304));
    ok1(bearing.value_degrees() < fixed(306));

    bearing = Bearing(b, a);
    ok1(bearing.value_degrees() > fixed(124));
    ok1(bearing.value_degrees() < fixed(126));

    distance = ProjectedDistance(a, b, a);
    ok1(is_zero(distance));
    distance = ProjectedDistance(a, b, b);
    ok1(distance > fixed(9120) && distance < fixed(9140));

    const GeoPoint middle(a.Longitude.Fraction(b.Longitude, fixed_half),
                          a.Latitude.Fraction(b.Latitude, fixed_half));
    distance = ProjectedDistance(a, b, middle);
    ok1(distance > fixed(9100/2) && distance < fixed(9140/2));

    fixed big_distance = Distance(a, c);
    ok1(big_distance > fixed(494000) && big_distance < fixed(495000));

    TestLinearDistance();

    return exit_status();
}
Example #6
0
static void
CalculateArc(AirspaceDatabase &airspace_database, TCHAR *Text,
             unsigned &NumberOfAirspacePoints)
{
  GEOPOINT Start;
  GEOPOINT End;
  double StartBearing;
  double EndBearing;
  double Radius;
  TCHAR *Comma = NULL;

  ReadCoords(&Text[3],&Start.Longitude , &Start.Latitude);

  Comma = _tcschr(Text,',');
  if(!Comma)
    return;

  ReadCoords(&Comma[1],&End.Longitude , &End.Latitude);

  GEOPOINT c; c.Longitude = CenterX; c.Latitude = CenterY;

  DistanceBearing(c, Start,
                  &Radius, &StartBearing);
  EndBearing = Bearing(c, End);
  TempPoint.Latitude  = Start.Latitude;
  TempPoint.Longitude = Start.Longitude;
  AddPoint(airspace_database, &TempPoint, &TempArea.NumPoints,
           NumberOfAirspacePoints);

  while(fabs(EndBearing-StartBearing) > 7.5) {
    StartBearing += Rotation *5 ;

    if(StartBearing > 360)
      StartBearing -= 360;
    if(StartBearing < 0)
      StartBearing += 360;

    if (bFillMode) { // Trig calcs not needed on first pass
      GEOPOINT c; c.Longitude = CenterX; c.Latitude = CenterY;
      FindLatitudeLongitude(c, StartBearing, Radius,
                            &TempPoint);
    }

    AddPoint(airspace_database, &TempPoint, &TempArea.NumPoints,
             NumberOfAirspacePoints);
  }

  TempPoint  = End;
  AddPoint(airspace_database, &TempPoint, &TempArea.NumPoints,
           NumberOfAirspacePoints);
}
Example #7
0
RangeAndRadial
AATPoint::GetTargetRangeRadial(fixed oldrange) const
{
  const auto fprev = GetPrevious()->GetLocationRemaining();
  const auto floc = GetLocation();
  const auto radialraw = (floc.Bearing(GetTargetLocation()) -
      fprev.Bearing(floc)).AsBearing();
  auto radial = radialraw.AsDelta();

  auto d = floc.Distance(GetTargetLocation());
  if (radial < -Angle::QuarterCircle() || radial > Angle::QuarterCircle())
    d = -d;

  const auto radius = negative(d)
    ? floc.Distance(GetLocationMin())
    : floc.Distance(GetLocationMax());
  const auto range = Clamp(d / radius, fixed(-1), fixed(1));

  if (oldrange == fixed(0) && range == fixed(0))
    radial = Angle::Zero();

  return RangeAndRadial{ range, radial };
}
Example #8
0
void Painter::DoSvgArc(const Pointf& rr, double xangle, int large, int sweep,
                       const Pointf& p1, const Pointf& p0)
{
	Pointf r(fabs(rr.x), fabs(rr.y));
	Xform2D m = Xform2D::Rotation(-xangle);
	Pointf d1 = m.Transform(0.5 * (p0 - p1));
	Pointf pr = r * r; 
	Pointf p = d1 * d1;
	double check = p.x / pr.x + p.y / pr.y;
	if(check > 1)
		r *= sqrt(check);
	m.x /= r.x;
	m.y /= r.y;
	Pointf q0 = m.Transform(p0);
	Pointf q1 = m.Transform(p1);
	double d = SquaredDistance(q0, q1);
	double sfactor_sq = 1.0 / d - 0.25;
	if(sfactor_sq < 0)
		sfactor_sq = 0;
	double sfactor = sqrt(sfactor_sq);
	if(sweep == large)
		sfactor = -sfactor;
	Pointf c(0.5 * (q0.x + q1.x) - sfactor * (q1.y - q0.y),
	         0.5 * (q0.y + q1.y) + sfactor * (q1.x - q0.x));
	double theta = Bearing(q0 - c);
	double th_sweep = Bearing(q1 - c) -  theta;
	if(th_sweep < 0 && sweep)
		th_sweep += 2 * M_PI;
	else
	if(th_sweep > 0 && !sweep)
		th_sweep -= 2 * M_PI;
	m = Xform2D::Rotation(xangle);
	m.x *= r;
	m.y *= r;
	m = Xform2D::Translation(c.x, c.y) * m;
	DoArc0(theta, th_sweep, m);
}
Example #9
0
static bool
ParseArcTNP(const TCHAR *Text, TempAirspaceType &temp_area)
{
  if (temp_area.points.empty())
    return false;

  // (ANTI-)CLOCKWISE RADIUS=34.95 CENTRE=N523333 E0131603 TO=N522052 E0122236

  GeoPoint from = temp_area.points.back();

  const TCHAR* parameter;
  if ((parameter = _tcsstr(Text, _T(" "))) == NULL)
    return false;
  if ((parameter = string_after_prefix_ci(parameter, _T(" CENTRE="))) == NULL)
    return false;
  ParseCoordsTNP(parameter, temp_area.Center);

  GeoPoint to;
  if ((parameter = _tcsstr(parameter, _T(" "))) == NULL)
    return false;
  parameter++;
  if ((parameter = _tcsstr(parameter, _T(" "))) == NULL)
    return false;
  if ((parameter = string_after_prefix_ci(parameter, _T(" TO="))) == NULL)
    return false;
  ParseCoordsTNP(parameter, to);

  Angle bearing_from;
  Angle bearing_to;
  fixed radius;

  static const fixed fixed_75 = fixed(7.5);
  const Angle BearingStep = Angle::degrees(temp_area.Rotation * fixed(5));

  DistanceBearing(temp_area.Center, from, &radius, &bearing_from);
  bearing_to = Bearing(temp_area.Center, to);

  GeoPoint TempPoint;
  while ((bearing_to - bearing_from).magnitude_degrees() > fixed_75) {
    bearing_from += BearingStep;
    bearing_from = bearing_from.as_bearing();
    FindLatitudeLongitude(temp_area.Center, bearing_from, radius, &TempPoint);
    temp_area.points.push_back(TempPoint);
  }

  return true;
}
Example #10
0
  void
  visit_leg_final(TASK_POINT &point0, const unsigned index0,
                  TASK_POINT &point1, const unsigned index1)
  {
    bool is_first = (point0.Index < point1.Index);
    int imin = min(point0.Index,point1.Index);
    int imax = max(point0.Index,point1.Index);
    // JMW AAT!
    double bearing = point0.OutBound;
    POINT sct1, sct2;

    canvas->select(dash_pen3);

    if (_task->getSettings().AATEnabled && !map_window->SettingsMap().TargetPan) {
      map_window->LonLat2Screen(point0.AATTargetLocation, sct1);
      map_window->LonLat2Screen(point1.AATTargetLocation, sct2);
      bearing = Bearing(point0.AATTargetLocation, point1.AATTargetLocation);

      // draw nominal track line
      canvas->line(way_points.get_calc(imin).Screen,
                   way_points.get_calc(imax).Screen);
    } else {
      sct1 = way_points.get_calc(point0.Index).Screen;
      sct2 = way_points.get_calc(point1.Index).Screen;
    }

    if (is_first) {
      canvas->line(sct1, sct2);
    } else {
      canvas->line(sct2, sct1);
    }

    // draw small arrow along task direction
    POINT p_p;
    POINT Arrow[3] = { {6,6}, {-6,6}, {0,0} };
    ScreenClosestPoint(sct1, sct2, orig, &p_p, IBLSCALE(25));
    PolygonRotateShift(Arrow, 2, p_p.x, p_p.y,
		       bearing-map_window->GetDisplayAngle());
    Arrow[2] = Arrow[1];
    Arrow[1] = p_p;

    canvas->select(pent1);
    canvas->polyline(Arrow, 3);
  };
Example #11
0
static void
CalculateArc(const TCHAR *Text, TempAirspaceType &temp_area)
{
  // 5 or -5, depending on direction
  const Angle BearingStep = Angle::degrees(temp_area.Rotation * fixed(5));

  // Read start coordinates
  GeoPoint Start;
  if (!ReadCoords(&Text[3], Start))
    return;

  // Skip comma character
  const TCHAR* Comma = _tcschr(Text, ',');
  if (!Comma)
    return;

  // Read end coordinates
  GeoPoint End;
  if (!ReadCoords(&Comma[1], End))
    return;

  // Determine start bearing and radius
  Angle StartBearing;
  fixed Radius;
  temp_area.Center.distance_bearing(Start, Radius, StartBearing);

  // Determine end bearing
  Angle EndBearing = Bearing(temp_area.Center, End);

  // Add first polygon point
  GeoPoint TempPoint = Start;
  temp_area.points.push_back(TempPoint);

  // Add intermediate polygon points
  while ((EndBearing - StartBearing).magnitude_degrees() > fixed_7_5) {
    StartBearing = (StartBearing + BearingStep).as_bearing();
    TempPoint = FindLatitudeLongitude(temp_area.Center, StartBearing, Radius);
    temp_area.points.push_back(TempPoint);
  }

  // Add last polygon point
  TempPoint = End;
  temp_area.points.push_back(TempPoint);
}
Example #12
0
static void
CalculateArc(const TCHAR *Text, TempAirspaceType &temp_area)
{
  GeoPoint Start;
  GeoPoint End;
  Angle StartBearing;
  fixed Radius;
  const TCHAR *Comma = NULL;
  GeoPoint TempPoint;
  static const fixed fixed_75 = fixed(7.5);
  const Angle BearingStep = Angle::degrees(temp_area.Rotation * fixed(5));

  ReadCoords(&Text[3], Start);

  Comma = _tcschr(Text, ',');
  if (!Comma)
    return;

  ReadCoords(&Comma[1], End);

  DistanceBearing(temp_area.Center, Start, &Radius, &StartBearing);
  Angle EndBearing = Bearing(temp_area.Center, End);
  TempPoint.Latitude = Start.Latitude;
  TempPoint.Longitude = Start.Longitude;
  temp_area.points.push_back(TempPoint);

  while ((EndBearing - StartBearing).magnitude_degrees() > fixed_75) {
    StartBearing += BearingStep;
    StartBearing = StartBearing.as_bearing();
    FindLatitudeLongitude(temp_area.Center, StartBearing, Radius, &TempPoint);
    temp_area.points.push_back(TempPoint);
  }

  TempPoint = End;
  temp_area.points.push_back(TempPoint);
}