示例#1
0
    private void ComputeSunPosition()
    {
      // See http://en.wikipedia.org/wiki/Position_of_the_Sun. (But these formulas seem to be a bit
      // more precise.)

      double meanAnomaly = 6.24 + 628.302 * _epoch2000Centuries;

      // Ecliptic longitude.
      _sunEclipticLongitude = 4.895048 + 628.331951 * _epoch2000Centuries + (0.033417 - 0.000084 * _epoch2000Centuries) * Math.Sin(meanAnomaly)
                            + 0.000351 * Math.Sin(2.0 * meanAnomaly);

      // Distance from earth in astronomical units.
      double geocentricDistance = 1.000140 - (0.016708 - 0.000042 * _epoch2000Centuries) * Math.Cos(meanAnomaly)
                                  - 0.000141 * Math.Cos(2.0 * meanAnomaly);

      // Sun position.
      Vector3D sunPositionEcliptic = ToCartesian(geocentricDistance, 0, _sunEclipticLongitude);
      Vector3D sunPositionEquatorial = EclipticToEquatorial * sunPositionEcliptic;

      // Note: The sun formula is already corrected by precession.
      SunPosition = _equatorialToWorldNoPrecession.TransformDirection(sunPositionEquatorial);
      Vector3D sunDirection = SunPosition.Normalized;

      // Convert from astronomical units to meters.
      const double au = 149597870700; // 1 au = 149,597,870,700 m
      SunPosition *= au;

      // Account for atmospheric refraction.
      double elevation = Math.Asin(sunDirection.Y);
      elevation = Refract(elevation);
      sunDirection.Y = Math.Sin(elevation);
      sunDirection.Normalize();
      SunDirectionRefracted = sunDirection;
    }