예제 #1
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());
}
예제 #2
0
파일: Canvas.cpp 프로젝트: Exadios/YCSoar
//------------------------------------------------------------------------------
void
Canvas::DrawAnnulus(int x, int y,
                    unsigned inner_r, unsigned outer_r,
                    Angle start, Angle end)
  {
  QPainterPath p;
  QRectF ri(x - inner_r, y - inner_r, 2 * inner_r, 2 * inner_r);
  QRectF ro(x - outer_r, y - outer_r, 2 * outer_r, 2 * outer_r);
  // Draw the inner radius of the annulus.
  p.arcMoveTo(ri, start.Degrees());
  p.arcTo(ri, start.Degrees(), end.Degrees() - start.Degrees());
  if (start != end)
    { // Only draw the end caps when needed.
    // The currentPosition() will be at the end of the inner circle. Draw
    // one side of the annulus.
    // \todo This doesn't work because Angle(360) != Angle(0)!
    double xx = (outer_r - inner_r) * cos(end.Radians()) +
                p.currentPosition().rx();
    double yy = (outer_r - inner_r) * -sin(end.Radians()) +
                p.currentPosition().ry();
    p.lineTo(xx, yy);
    }
  else
    p.arcMoveTo(ro, end.Degrees());  // Set up for the outer circle.
  // The currentPosition() will be at the 'end' of the outer circle. Draw the
  // outer to the start.
  p.arcTo(ro, end.Degrees(), start.Degrees() - end.Degrees());
  if (start != end)
    {// And close it off to finish up.
    p.closeSubpath();
    }
  this->pushObject(p, this->pen(), this->brush());
  }
예제 #3
0
double 
MoonPhaseFunc::operator()( double julianDay )
{
    Angle phase = LunarPhase( julianDay );
    Angle diff = m_phaseAngle - phase;
    return diff.Radians();
}
AxisAngle<T> 
RotationMatrix3<T>::GetAxisAngle( ) const
{
    Angle angle = ArcCos( (Trace() - 1.) / 2. );
    Vector3<T> axis;
    if ( angle.Radians() <= 0. )
        axis = Vector3<T>::UnitX;   //arbitrary: there is no rotation.
    else if ( angle.Radians() < M_PI )
    {
        axis.Set( m_matrix( 2, 1 ) - m_matrix( 1, 2 ),
                  m_matrix( 0, 2 ) - m_matrix( 2, 0 ),
                  m_matrix( 1, 0 ) - m_matrix( 0, 1 ) );
        axis.Normalize( );
    }
    else
    {
        int i0 = 0;
        int i1 = 1;
        int i2 = 2;
        T maxD = m_matrix( 0, 0 );
        if ( m_matrix( 1, 1 ) > maxD )
        {
            i0 = 1;
            i1 = 0;
            maxD = m_matrix( 1, 1 );
        }
        if ( m_matrix( 2, 2 ) > maxD )
        {
            i0 = 2;
            i1 = 0;
            i2 = 1;
        }
        T axisComps[3];
        axisComps[i0] = static_cast<T>( 0.5 ) * std::sqrt( m_matrix( i0, i0 )
                                         - m_matrix( i1, i1 )
                                         - m_matrix( i2, i2 )
                                         + static_cast<T>( 1. ) );
        axisComps[i1] = m_matrix( i1, i0 )
                / (static_cast<T>( 2. ) * axisComps[i0]);
        axisComps[i2] = m_matrix( i1, i0 )
                / (static_cast<T>( 2. ) * axisComps[i0]);
        axis.Set( axisComps[0], axisComps[1], axisComps[2] );
    }
    return  AxisAngle<T>( axis, angle );
}
예제 #5
0
GeoPoint
SectorZone::GetBoundaryParametric(fixed t) const
{
    const Angle sweep = (EndRadial - StartRadial).AsBearing();
    const fixed l = Radius;
    const fixed c1 = sweep.Radians() * Radius;
    const fixed tt = t * (c1 + 2 * l);
    Angle a;
    fixed d;
    if (tt < l) {
        d = (tt / l) * Radius;
        a = StartRadial;
    } else if (tt < l + c1) {
        d = Radius;
        a = StartRadial + Angle::Radians(((tt - l) / c1) * sweep.Radians());
    } else {
        d = Radius - (tt - l - c1) / l * Radius;
        a = EndRadial;
    }
    return GeoVector(d, a).EndPoint(get_location());
}
예제 #6
0
GeoPoint
SectorZone::GetBoundaryParametric(fixed t) const
{
  const Angle sweep = (end_radial - start_radial).AsBearing();
  const fixed l = GetRadius();
  const fixed c1 = sweep.Radians() * GetRadius();
  const fixed tt = t * (c1 + 2 * l);
  Angle a;
  fixed d;
  if (tt < l) {
    d = (tt / l) * GetRadius();
    a = start_radial;
  } else if (tt < l + c1) {
    d = GetRadius();
    a = start_radial + Angle::Radians(((tt - l) / c1) * sweep.Radians());
  } else {
    d = GetRadius() - (tt - l - c1) / l * GetRadius();
    a = end_radial;
  }
  return GeoVector(d, a).EndPoint(GetReference());
}
예제 #7
0
파일: Canvas.cpp 프로젝트: Exadios/YCSoar
//------------------------------------------------------------------------------
inline Angle
Canvas::normalize(const Angle& a) const
  {
  double r = fmod(a.Radians(), 2.0 * M_PI);
  Angle ra = Angle::Radians(r);
#ifndef NDEBUG
  double ad = a.Degrees();
  double rd = ra.Degrees();
  std::cerr << __LINE__ << ": " << ad << ", " << rd << std::endl;
#endif
  return (ra);
  }
예제 #8
0
void
UpdateInfoBoxCircleDiameter(InfoBoxData &data)
{
  if (!CommonInterface::Basic().airspeed_available.IsValid()) {
    data.SetInvalid();
    return;
  }

  const Angle turn_rate =
    CommonInterface::Calculated().turn_rate_heading_smoothed.Absolute();

  // deal with div zero and small turn rates
  if (turn_rate < Angle::Degrees(1)) {
    data.SetInvalid();
    return;
  }

  const fixed circle_diameter = CommonInterface::Basic().true_airspeed
     / turn_rate.Radians()
     * fixed(2); // convert turn rate to radians/s and double it to get estimated circle diameter

  if (circle_diameter > fixed (2000)){ // arbitrary estimated that any diameter bigger than 2km will not be interesting
    data.SetInvalid();
    return;
  }

  TCHAR buffer[32];
  Unit unit = FormatSmallUserDistance(buffer, circle_diameter, false, 0);
  data.SetValue (buffer);
  data.SetValueUnit(unit);

  const fixed circle_duration =
    Angle::FullCircle().Native() / turn_rate.Native();

  StaticString<16> duration_buffer;
  duration_buffer.Format(_T("%u s"), int(circle_duration));
  _tcscpy (buffer, duration_buffer);
  data.SetComment (buffer);
}
예제 #9
0
 gcc_const
 static int16_t Import(Angle x) {
   return (int16_t)(x.Radians() * 4096);
 }
예제 #10
0
SunEphemeris::Result
SunEphemeris::CalcSunTimes(const GeoPoint &location,
                           const BrokenDateTime &date_time,
                           const fixed time_zone)
{
  Result result;

  assert(date_time.Plausible());

  fixed days_to_j2000 = FNday(date_time);

  Angle l = GetMeanSunLongitude(days_to_j2000);

  // Use GetEclipticLongitude to find the ecliptic longitude of the Sun
  Angle lambda = GetEclipticLongitude(days_to_j2000, l);

  // Obliquity of the ecliptic
  Angle obliquity = Angle::Degrees(fixed(23.439) - fixed(.0000004) * days_to_j2000);

  // Find the RA and DEC of the Sun
  Angle alpha = Angle::FromXY(lambda.cos(), obliquity.cos() * lambda.sin());
  Angle delta = Angle::asin(obliquity.sin() * lambda.sin());

  // Find the Equation of Time in minutes
  // Correction suggested by David Smith
  fixed ll = (l - alpha).Radians();
  if (l.Radians() < fixed_pi)
    ll += fixed_two_pi;

  fixed equation = fixed(1440) * (fixed(1) - ll / fixed_two_pi);

  Angle hour_angle = GetHourAngle(location.latitude, delta);
  Angle hour_angle_twilight = GetHourAngleTwilight(location.latitude, delta);

  result.azimuth = CalculateAzimuth(location, date_time, time_zone, delta);

  // length of twilight in hours
  fixed twilight_hours = (hour_angle_twilight - hour_angle).Hours();

  // Conversion of angle to hours and minutes
  result.day_length = Double(hour_angle.Hours());

  if (result.day_length < fixed(0.0001))
    // arctic winter
    result.day_length = fixed(0);

  result.time_of_sunrise = fixed(12) - hour_angle.Hours() + time_zone
    - location.longitude.Degrees() / 15 + equation / 60;

  if (result.time_of_sunrise > fixed(24))
    result.time_of_sunrise -= fixed(24);

  result.time_of_sunset = result.time_of_sunrise + result.day_length;
  result.time_of_noon = result.time_of_sunrise + hour_angle.Hours();

  // morning twilight begin
  result.morning_twilight = result.time_of_sunrise - twilight_hours;
  // evening twilight end
  result.evening_twilight = result.time_of_sunset + twilight_hours;

  return result;
}
예제 #11
0
 /**
  * Convert a an angle on Earth's surface to a pixel distance.
  */
 gcc_pure
 fixed AngleToPixels(Angle angle) const {
   return fast_mult(angle.Radians(), draw_scale, 12);
 }
예제 #12
0
 /**
  * Convert a an angle on Earth's surface to a pixel distance.
  */
 gcc_pure
 double AngleToPixels(Angle angle) const {
   return angle.Radians() * draw_scale;
 }
예제 #13
0
 /**
  * Convert an angle to the according distance on earth's surface [m],
  * assuming the earth is a sphere.
  */
 constexpr
 static inline fixed
 AngleToEarthDistance(Angle angle)
 {
   return angle.Radians() * REARTH;
 }