# Geographical Point of the Sun

I want to draw a Sun in a 3d scene, so I figured the easiest way would be to calculate the latitude and longitude of the point perpendicular to Sun position and then just move it "up".

As a starting point, I want to calculate it's equatorial coordinates: declination and right ascension.

Here's my code (in Swift):

import Foundation

class Astronomy {

static func julianDays(since: Date) -> Double {
return since.timeIntervalSince1970 / 86400 + 2440587.5
}

static func daysSinceJ2000(for date: Date) -> Double {
return julianDays(since: date) - 2451545
}

static func sunAxialTilt(for daysSinceJ200: Double) -> Double {
return 23.4393 - 3.563e-7 * daysSinceJ200
}

static func sunEquatorialPosition(on date: Date) -> (declination: Double, RA: Double, distance: Double) {
let daysSinceGreenwichNoon = daysSinceJ2000(for: date)
var meanLongitude = 280.460 + 0.9856474*daysSinceGreenwichNoon
var meanAnomaly = 357.528 + 0.9856003*daysSinceGreenwichNoon
meanLongitude = meanLongitude.rangedUpTo360
meanAnomaly = meanAnomaly.rangedUpTo360

let axialTilt = sunAxialTilt(for: daysSinceGreenwichNoon)

return (declination: declination.degrees, RA: rightAscension.degrees, distance: distanceToEarth)
}
}

extension Double {
return self * .pi / 180
}

var degrees: Double {
return self  * 180 / .pi
}

var rangedUpTo360: Double {
let multiples = (self/360).rounded(.down)
return self - 360*multiples
}
}


However, it does not seem to be working correctly. As of the time I write this article, the result is declination -16.98772292697088, RA -44.80674952684117. Compared with https://theskylive.com/sun-info the declination is about right (-17° 03’ 38”), but right ascension is way off: 20h 59m 43s, which is 314.93 degrees according to this site

What went wrong?

Edit: As it turned out nothing was wrong, I can get to the second part: calculating the geographical point. (the title suggests it after all)

AFAIK for latitude, I can use declination as is and for longitude, I need to calculate Greenwich Hour Angle(GHA)

After examining several articles, I found these equations:

SHA[°] = 360 – 15 · RA[h]
GHAAries[°] = 15 · GST[h]
GHA = SHA + GHAAries


For my case, I suppose I may use RA as is, without multiplying its hour component by 15. What keeps me a bit puzzled is GST:

1. May I use Greenwich Mean Sidereal Time instead if I don't need the calculations to be super precise?
2. Is there any "GST for dummies"? All the calculations I found rely on some floating second offset, I found this table but have no idea how to use it.
• I don't think anything went wrong ... 314.93 - -44.807 is roughly 360 degrees ... meaning it's the same right ascension. The reason for slight inaccuracy likely has things to do with floating-point integer accuracy and the fact that the Sun's right ascension is very difficult to very accurately measure in practice. – Tosic Feb 1 '19 at 22:43
• I'm voting to close this question as off-topic because it's about coding rather than astronomy. – Chappo Hasn't Forgotten Monica Feb 2 '19 at 6:57
• @Tosic ahh I see, so I have to add 360 if my resulting value would be < 0, thank you very much! – bitemybyte Feb 2 '19 at 8:52
• @Chappo I disagree, it is not about how to code something, but about interpreting the results, as the code is essentially math – bitemybyte Feb 2 '19 at 8:52
• @Chappo I also disagree with the close; a large number of formulas in astronomy require renormalization into the range 0..360 (or 0..2PI in radians). Some texts are good at telling you that you need to do this, some aren't. So a question that illustrates the need to renormalize quantities such as RA or GST or planetary longitudes to get the correct answer is useful IMHO. – astrosnapper Feb 5 '19 at 1:17