Git Product home page Git Product logo

Comments (2)

Starainrt avatar Starainrt commented on June 14, 2024 2

真太阳时只和经度有关,与纬度无关
此问题有两种计算方法

  1. 从真平太阳时定义上看:真太阳时=当地平太阳时+均时差
    当地平太阳时可以通过给时间、时区和经度算出,均时差通过公式也能得到,两者相加即为当地朕太阳时

  2. 另一方面,天文意义上看,真太阳时就是太阳的天球位置与子午线的夹角,即太阳时角(日晷影)
    太阳上中天时,太阳时角为0度,对应的真太阳时为12时,也就是真太阳时=太阳时角+12小时

两种方法对应的代码如下

package main

import (
	"fmt"
	"github.com/starainrt/astro/basic"
	"github.com/starainrt/astro/sun"
	"math"
	"time"
)

func main() {
	cst := time.FixedZone("CST", 8*3600)
	date := time.Date(2022, 1, 1, 0, 0, 0, 0, cst)
	fmt.Println(date, "\n",
		ApparentSolarTime(date, 115), "\n",
		ApparentSolarTime2(date, 115))
}

// 方法一:真太阳时=当地平太阳时+均时差
func ApparentSolarTime(date time.Time, lon float64) time.Time {
	//取世界时,用于计算均时差
	jde := basic.Date2JDE(date.UTC())
	LocalTimezone := int(lon * 3600.00 / 15.0)
	//pTime:获取当地经度时区的平太阳时
	pTime := date.In(time.FixedZone("LTZ", LocalTimezone))
	//真太阳时=平太阳时+均时差
	return pTime.Add(time.Duration(basic.SunTime(jde) * 3600 * 1000 * 1000 * 1000))
}


// 方法二 真太阳时=太阳时角+12小时
func ApparentSolarTime2(date time.Time, lon float64) time.Time {
	//真太阳时=太阳时角+12小时
	trueTime := (sun.HourAngle(date, lon, 0) + 180) / 15
	if trueTime > 24 {
		trueTime -= 24
	}
	//真太阳时的分
	minute := (trueTime - math.Floor(trueTime)) * 60
	//真太阳时的秒
	second := (minute - math.Floor(minute)) * 60
	//当地经度下的本地时区
	trueSunTime := date.In(time.FixedZone("LTZ", int(lon*3600.00/15.0)))
	if trueSunTime.Hour()-int(trueTime) > 12 {
		trueSunTime = trueSunTime.Add(time.Hour * 24)
	} else if int(trueTime)-trueSunTime.Hour() > 12 {
		trueSunTime = trueSunTime.Add(-time.Hour * 24)
	}
	return time.Date(trueSunTime.Year(), trueSunTime.Month(), trueSunTime.Day(),
		int(trueTime), int(minute), int(second), int((second-math.Floor(second))*1000000000),
		time.FixedZone("LTZ", int(lon*3600.00/15.0)))
}

运行结果如下:

2022-01-01 00:00:00 +0800 CST   //北京时间
2021-12-31 23:36:51.633708344 +0740 LTZ //当地真太阳时 方法一
2021-12-31 23:36:51.373404123 +0740 LTZ  //当地真太阳时 方法二

两个方法0.3秒的差异在于迭代次数的不同,方法二的精度会更高,但是速度会更慢。
计算结果的时区均为当地经度时区,非传入时的标准时区

from astro.

Aquarian-Age avatar Aquarian-Age commented on June 14, 2024

多谢 选择第二个了

from astro.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.