improve rise/down calc

This commit is contained in:
2022-05-10 22:24:10 +08:00
parent c5f34d3ab8
commit 7604fabf8f
8 changed files with 276 additions and 82 deletions
+83 -59
View File
@@ -1179,28 +1179,29 @@ func GetBanTime(JD, Lon, Lat, TZ, An float64) float64 {
JD = math.Floor(JD) + 1.5
ntz := math.Round(Lon / 15)
tztime := GetSunTZTime(JD, Lon, ntz)
dec := HSunSeeDec(tztime)
tmp := -Tan((math.Abs(Lat)+An)*(Lat/math.Abs(Lat))) * Tan(dec)
if math.Abs(tmp) > 1 {
if SunHeight(tztime, Lon, Lat, ntz) < An {
return -2 //极
}
if SunHeight(tztime-0.5, Lon, Lat, ntz) > An {
return -1 //极昼
if SunHeight(tztime, Lon, Lat, ntz) < An {
return -2 //极夜
}
if SunHeight(tztime+0.5, Lon, Lat, ntz) > An {
return -1 //极
}
tmp := (Sin(An) - Sin(HSunSeeDec(tztime))*Sin(Lat)) / (Cos(HSunSeeDec(tztime)) * Cos(Lat))
var sundown float64
if math.Abs(tmp) <= 1 && Lat < 85 {
rzsc := ArcCos(tmp) / 15
sundown = tztime + rzsc/24.0 + 35.0/24.0/60.0
} else {
sundown = tztime
i := 0
for LowSunHeight(sundown, Lon, Lat, ntz) > An {
i++
sundown += 15.0 / 60.0 / 24.0
if i > 48 {
break
}
}
}
tmp = -Tan(Lat) * Tan(dec)
rzsc := ArcCos(tmp) / 15
sunrise := tztime + rzsc/24.0 + 35.0/24.0/60.0
i := 0
for LowSunHeight(sunrise, Lon, Lat, ntz) < An {
i++
sunrise -= 15 / 60 / 24
if i > 12 {
break
}
}
JD1 := sunrise - 5.00/24.00/60.00
JD1 := sundown - 5.00/24.00/60.00
for {
JD0 := JD1
stDegree := SunHeight(JD0, Lon, Lat, ntz) - An
@@ -1217,25 +1218,26 @@ func GetAsaTime(JD, Lon, Lat, TZ, An float64) float64 {
JD = math.Floor(JD) + 1.5
ntz := math.Round(Lon / 15)
tztime := GetSunTZTime(JD, Lon, ntz)
dec := HSunSeeDec(tztime)
tmp := -Tan((math.Abs(Lat)+An)*(Lat/math.Abs(Lat))) * Tan(dec)
if math.Abs(tmp) > 1 {
if SunHeight(tztime, Lon, Lat, ntz) < An {
return -2 //极夜
}
if SunHeight(tztime-0.5, Lon, Lat, ntz) > An {
return -1 //极昼
}
if SunHeight(tztime, Lon, Lat, ntz) < An {
return -2 //极夜
}
tmp = -Tan(Lat) * Tan(dec)
rzsc := ArcCos(tmp) / 15
sunrise := tztime - rzsc/24 - 25.0/24.0/60.0
i := 0
for LowSunHeight(sunrise, Lon, Lat, ntz) > An {
i++
sunrise -= 15 / 60 / 24
if i > 12 {
break
if SunHeight(tztime-0.5, Lon, Lat, ntz) > An {
return -1 //极昼
}
tmp := (Sin(An) - Sin(HSunSeeDec(tztime))*Sin(Lat)) / (Cos(HSunSeeDec(tztime)) * Cos(Lat))
var sunrise float64
if math.Abs(tmp) <= 1 && Lat < 85 {
rzsc := ArcCos(tmp) / 15
sunrise = tztime - rzsc/24 - 25.0/24.0/60.0
} else {
sunrise = tztime
i := 0
for LowSunHeight(sunrise, Lon, Lat, ntz) > An {
i++
sunrise -= 15.0 / 60.0 / 24.0
if i > 48 {
break
}
}
}
JD1 := sunrise - 5.00/24.00/60.00
@@ -1275,18 +1277,30 @@ func GetSunRiseTime(JD, Lon, Lat, TZ, ZS, HEI float64) float64 {
}
An = An - HeightDegreeByLat(HEI, Lat)
tztime := GetSunTZTime(JD, Lon, ntz)
dec := HSunSeeDec(tztime)
tmp := -Tan(Lat) * Tan(dec)
if math.Abs(tmp) > 1 {
if SunHeight(tztime, Lon, Lat, ntz) < 0 {
return -2 //极
}
if SunHeight(tztime-0.5, Lon, Lat, ntz) > 0 {
return -1 //极昼
if SunHeight(tztime, Lon, Lat, ntz) < An {
return -2 //极夜
}
if SunHeight(tztime-0.5, Lon, Lat, ntz) > An {
return -1 //极
}
//(sin(ho)-sin(φ)*sin(δ2))/(cos(φ)*cos(δ2))
tmp := (Sin(An) - Sin(HSunSeeDec(tztime))*Sin(Lat)) / (Cos(HSunSeeDec(tztime)) * Cos(Lat))
var sunrise float64
if math.Abs(tmp) <= 1 && Lat < 85 {
rzsc := ArcCos(tmp) / 15
sunrise = tztime - rzsc/24 - 25.0/24.0/60.0
} else {
sunrise = tztime
i := 0
//TODO:使用二分法计算
for LowSunHeight(sunrise, Lon, Lat, ntz) > An {
i++
sunrise -= 15.0 / 60.0 / 24.0
if i > 48 {
break
}
}
}
rzsc := ArcCos(tmp) / 15
sunrise := tztime - rzsc/24 - 5.0/24.0/60.0
JD1 := sunrise
for {
JD0 := JD1
@@ -1308,19 +1322,29 @@ func GetSunDownTime(JD, Lon, Lat, TZ, ZS, HEI float64) float64 {
}
An = An - HeightDegreeByLat(HEI, Lat)
tztime := GetSunTZTime(JD, Lon, ntz)
dec := HSunSeeDec(tztime)
tmp := -Tan(Lat) * Tan(dec)
if math.Abs(tmp) > 1 {
if SunHeight(tztime, Lon, Lat, ntz) < 0 {
return -2 //极
}
if SunHeight(tztime+0.5, Lon, Lat, ntz) > 0 {
return -1 //极昼
if SunHeight(tztime, Lon, Lat, ntz) < An {
return -2 //极夜
}
if SunHeight(tztime+0.5, Lon, Lat, ntz) > An {
return -1 //极
}
tmp := (Sin(An) - Sin(HSunSeeDec(tztime))*Sin(Lat)) / (Cos(HSunSeeDec(tztime)) * Cos(Lat))
var sundown float64
if math.Abs(tmp) <= 1 && Lat < 85 {
rzsc := ArcCos(tmp) / 15
sundown = tztime + rzsc/24.0 + 35.0/24.0/60.0
} else {
sundown = tztime
i := 0
for LowSunHeight(sundown, Lon, Lat, ntz) > An {
i++
sundown += 15.0 / 60.0 / 24.0
if i > 48 {
break
}
}
}
rzsc := ArcCos(tmp) / 15.0
sunrise := tztime + rzsc/24 - 5.0/24.0/60.0
JD1 := sunrise
JD1 := sundown
for {
JD0 := JD1
stDegree := SunHeight(JD0, Lon, Lat, ntz) - An