Files
astro/basic/saturn.go
T

193 lines
5.5 KiB
Go
Raw Permalink Normal View History

2019-10-24 10:44:21 +08:00
package basic
import (
"math"
"b612.me/astro/planet"
. "b612.me/astro/tools"
)
2026-05-01 22:38:44 +08:00
func SaturnL(jd float64) float64 {
return planet.WherePlanet(5, 0, jd)
2019-10-24 10:44:21 +08:00
}
2026-05-01 22:38:44 +08:00
func SaturnB(jd float64) float64 {
return planet.WherePlanet(5, 1, jd)
2019-10-24 10:44:21 +08:00
}
2026-05-01 22:38:44 +08:00
func SaturnR(jd float64) float64 {
return planet.WherePlanet(5, 2, jd)
2019-10-24 10:44:21 +08:00
}
2026-05-01 22:38:44 +08:00
func ASaturnX(jd float64) float64 {
l := SaturnL(jd)
b := SaturnB(jd)
r := SaturnR(jd)
el := planet.WherePlanet(-1, 0, jd)
eb := planet.WherePlanet(-1, 1, jd)
er := planet.WherePlanet(-1, 2, jd)
2019-10-24 10:44:21 +08:00
x := r*Cos(b)*Cos(l) - er*Cos(eb)*Cos(el)
return x
}
2026-05-01 22:38:44 +08:00
func ASaturnY(jd float64) float64 {
2019-10-24 10:44:21 +08:00
2026-05-01 22:38:44 +08:00
l := SaturnL(jd)
b := SaturnB(jd)
r := SaturnR(jd)
el := planet.WherePlanet(-1, 0, jd)
eb := planet.WherePlanet(-1, 1, jd)
er := planet.WherePlanet(-1, 2, jd)
2019-10-24 10:44:21 +08:00
y := r*Cos(b)*Sin(l) - er*Cos(eb)*Sin(el)
return y
}
2026-05-01 22:38:44 +08:00
func ASaturnZ(jd float64) float64 {
//l := SaturnL(jd)
b := SaturnB(jd)
r := SaturnR(jd)
// el := planet.WherePlanet(-1, 0, jd)
eb := planet.WherePlanet(-1, 1, jd)
er := planet.WherePlanet(-1, 2, jd)
2019-10-24 10:44:21 +08:00
z := r*Sin(b) - er*Sin(eb)
return z
}
2026-05-01 22:38:44 +08:00
func ASaturnXYZ(jd float64) (float64, float64, float64) {
l := SaturnL(jd)
b := SaturnB(jd)
r := SaturnR(jd)
el := planet.WherePlanet(-1, 0, jd)
eb := planet.WherePlanet(-1, 1, jd)
er := planet.WherePlanet(-1, 2, jd)
2019-10-24 10:44:21 +08:00
x := r*Cos(b)*Cos(l) - er*Cos(eb)*Cos(el)
y := r*Cos(b)*Sin(l) - er*Cos(eb)*Sin(el)
z := r*Sin(b) - er*Sin(eb)
return x, y, z
}
2026-05-01 22:38:44 +08:00
func SaturnApparentRa(jd float64) float64 {
lo, bo := SaturnApparentLoBo(jd)
eps := TrueObliquity(jd)
ra := math.Atan2((Sin(lo)*Cos(eps) - Tan(bo)*Sin(eps)), Cos(lo))
2019-10-24 10:44:21 +08:00
ra = ra * 180 / math.Pi
return Limit360(ra)
}
2026-05-01 22:38:44 +08:00
func SaturnApparentDec(jd float64) float64 {
lo, bo := SaturnApparentLoBo(jd)
eps := TrueObliquity(jd)
dec := ArcSin(Sin(bo)*Cos(eps) + Cos(bo)*Sin(eps)*Sin(lo))
2019-10-24 10:44:21 +08:00
return dec
}
2026-05-01 22:38:44 +08:00
func SaturnApparentRaDec(jd float64) (float64, float64) {
lo, bo := SaturnApparentLoBo(jd)
eps := TrueObliquity(jd)
ra := math.Atan2((Sin(lo)*Cos(eps) - Tan(bo)*Sin(eps)), Cos(lo))
2019-10-24 10:44:21 +08:00
ra = ra * 180 / math.Pi
2026-05-01 22:38:44 +08:00
dec := ArcSin(Sin(bo)*Cos(eps) + Cos(bo)*Sin(eps)*Sin(lo))
2019-10-24 10:44:21 +08:00
return Limit360(ra), dec
}
2026-05-01 22:38:44 +08:00
func EarthSaturnAway(jd float64) float64 {
return planetEarthAwayExplicitN(5, jd, -1)
2019-10-24 10:44:21 +08:00
}
2026-05-01 22:38:44 +08:00
func SaturnApparentLo(jd float64) float64 {
geo, _ := planetApparentGeocentricPositionN(5, jd, -1)
return geo.lo
2019-10-24 10:44:21 +08:00
}
2026-05-01 22:38:44 +08:00
func SaturnApparentBo(jd float64) float64 {
geo, _ := planetApparentGeocentricPositionN(5, jd, -1)
return geo.bo
2019-10-24 10:44:21 +08:00
}
2026-05-01 22:38:44 +08:00
func SaturnApparentLoBo(jd float64) (float64, float64) {
geo, _ := planetApparentGeocentricPositionN(5, jd, -1)
return geo.lo, geo.bo
2019-10-24 10:44:21 +08:00
}
2026-05-01 22:38:44 +08:00
func SaturnMag(jd float64) float64 {
return SaturnMagN(jd, -1)
2019-10-24 10:44:21 +08:00
}
func SaturnHeight(jde, lon, lat, timezone float64) float64 {
// 转换为世界时
utcJde := jde - timezone/24.0
// 计算视恒星时
ra, dec := SaturnApparentRaDec(TD2UT(utcJde, true))
st := Limit360(ApparentSiderealTime(utcJde)*15 + lon)
// 计算时角
2026-05-01 22:38:44 +08:00
hourAngle := Limit360(st - ra)
// 高度角、时角与天球座标三角转换公式
2026-05-01 22:38:44 +08:00
// sin(h)=sin(lat)*sin(dec)+cos(dec)*cos(lat)*cos(hourAngle)
sinHeight := Sin(lat)*Sin(dec) + Cos(dec)*Cos(lat)*Cos(hourAngle)
return ArcSin(sinHeight)
}
func SaturnAzimuth(jde, lon, lat, timezone float64) float64 {
// 转换为世界时
utcJde := jde - timezone/24.0
// 计算视恒星时
ra, dec := SaturnApparentRaDec(TD2UT(utcJde, true))
st := Limit360(ApparentSiderealTime(utcJde)*15 + lon)
// 计算时角
2026-05-01 22:38:44 +08:00
hourAngle := Limit360(st - ra)
// 三角转换公式
2026-05-01 22:38:44 +08:00
tanAzimuth := Sin(hourAngle) / (Cos(hourAngle)*Sin(lat) - Tan(dec)*Cos(lat))
azimuth := ArcTan(tanAzimuth)
if azimuth < 0 {
if hourAngle/15 < 12 {
return azimuth + 360
}
2026-05-01 22:38:44 +08:00
return azimuth + 180
}
2026-05-01 22:38:44 +08:00
if hourAngle/15 < 12 {
return azimuth + 180
}
2026-05-01 22:38:44 +08:00
return azimuth
}
2026-05-01 22:38:44 +08:00
func SaturnHourAngle(jd, lon, timezone float64) float64 {
siderealLongitude := Limit360(ApparentSiderealTime(jd-timezone/24)*15 + lon)
hourAngle := siderealLongitude - SaturnApparentRa(TD2UT(jd-timezone/24.0, true))
if hourAngle < 0 {
hourAngle += 360
}
2026-05-01 22:38:44 +08:00
return hourAngle
}
func SaturnCulminationTime(jde, lon, timezone float64) float64 {
//jde 世界时,非力学时,当地时区 0时,无需转换力学时
//ra,dec 瞬时天球座标,非J2000等时间天球坐标
jde = math.Floor(jde) + 0.5
2026-05-01 22:38:44 +08:00
estimateJD := jde + Limit360(360-SaturnHourAngle(jde, lon, timezone))/15.0/24.0*0.99726851851851851851
normalizedHourAngle := func(jde, lon, timezone float64) float64 {
currentHourAngle := SaturnHourAngle(jde, lon, timezone)
if currentHourAngle < 180 {
currentHourAngle += 360
}
2026-05-01 22:38:44 +08:00
return currentHourAngle
}
for {
2026-05-01 22:38:44 +08:00
prevJD := estimateJD
hourAngleDelta := normalizedHourAngle(prevJD, lon, timezone) - 360
hourAngleSlope := (normalizedHourAngle(prevJD+0.000005, lon, timezone) - normalizedHourAngle(prevJD-0.000005, lon, timezone)) / 0.00001
estimateJD = prevJD - hourAngleDelta/hourAngleSlope
if math.Abs(estimateJD-prevJD) <= 0.00001 {
break
}
}
2026-05-01 22:38:44 +08:00
return estimateJD
}
2026-05-01 22:38:44 +08:00
func SaturnRiseTime(jd, lon, lat, timezone, aeroCorrection, observerHeight float64) (float64, error) {
return saturnRiseDown(jd, lon, lat, timezone, aeroCorrection, observerHeight, true)
}
2026-05-01 22:38:44 +08:00
func SaturnSetTime(jd, lon, lat, timezone, aeroCorrection, observerHeight float64) (float64, error) {
return saturnRiseDown(jd, lon, lat, timezone, aeroCorrection, observerHeight, false)
}
2026-05-01 22:38:44 +08:00
func saturnRiseDown(jd, lon, lat, timezone, aeroCorrection, observerHeight float64, isRise bool) (float64, error) {
return planetRiseDown(jd, lon, lat, timezone, aeroCorrection, observerHeight, isRise, SaturnCulminationTime, SaturnHeight, SaturnApparentDec)
}