updateSunPositionFromRealTime method

void updateSunPositionFromRealTime()

Calculates and sets the sun's position based on real-time.

This uses astronomical calculations to determine where the sun is currently positioned over the Earth.

Example usage:

controller.updateSunPositionFromRealTime();

Implementation

void updateSunPositionFromRealTime() {
  final now = DateTime.now().toUtc();

  // Calculate the day of the year
  final startOfYear = DateTime.utc(now.year, 1, 1);
  final dayOfYear = now.difference(startOfYear).inDays + 1;

  // Calculate the sun's declination (latitude) based on the day of the year
  // This approximates the Earth's axial tilt effect
  final declination = -23.45 * math.cos(2 * math.pi * (dayOfYear + 10) / 365);

  // Calculate the sun's longitude based on the current time
  // The sun moves 15 degrees per hour (360 / 24)
  final hours = now.hour + now.minute / 60.0 + now.second / 3600.0;
  final longitude = 180 - (hours * 15); // Noon is at 0 degrees, moves west

  sunLatitude = declination;
  sunLongitude = longitude;
  notifyListeners();
}