日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

4字节 经纬度_Swift4 经纬度计算日出日落时间

發(fā)布時間:2023/12/18 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 4字节 经纬度_Swift4 经纬度计算日出日落时间 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

import UIKitclassPGSun: NSObject {structSunriseset {

var sunrise= "07:00" //日出

var sunset = "18:30" //日落

init(sunrise:String, sunset:String) {

self.sunrise=sunrise

self.sunset=sunset

}

}

var start: Double= 0.0var sRA: Double= 0.0var sdec: Double= 0.0var sr: Double= 0.0var lon: Double= 0.0var end: Double= 0.0

private let Inv360: Double = 1.0 / 360.0

private let Degrad: Double = .pi / 180.0

private let Radge: Double = 180.0 /.pi///根據(jù)經(jīng)緯度計(jì)算日出和日落時間 -誤差2分鐘///

///- Parameters:///- Returns: Sunriseset

class func sun(longitude:Double, latitude:Double)->Sunriseset{

let sun=PGSun()returnsun.getSunTimeAtDate(d: Date(), longitude: longitude, latitude: latitude)

}

func getSunTimeAtDate(d:Date , longitude:Double ,latitude:Double)->Sunriseset{

let xcts: Int=days(since_2000_Jan_0: d)

let dic=getSunTime(xcts, lon: longitude, lat: latitude)returndic

}

func getSunTime(_ day: Int, lon longitude: Double, lat latitude: Double)->Sunriseset {

_= self.sunRiset(day, long:longitude, lat:latitude ,altit: -35.0 / 60.0, limb:1, trise:self.start, tset:self.end)

let sunrise=toLocalTime(self.start)

let sunset=toLocalTime(self.end)

let sun=Sunriseset(sunrise: sunrise, sunset: sunset)returnsun

}

func toLocalTime(_ utTime:Double)->String {

var hour=Int(floor(utTime))

var temp= utTime -Double(hour)

hour+= 8;

temp= temp * 60;

let minute=Int(floor(temp))return String(format: "%02d:%02d", hour,minute)

}

func days(since_2000_Jan_0 d: Date)->Int {//距離2000-01-01的天數(shù)

let dateStr = "2000-01-01"let dateFormatter=DateFormatter()

dateFormatter.dateFormat= "yyyy-MM-dd"let date: Date? =dateFormatter.date(from: dateStr)

var time: TimeInterval? =nilif let aDate =date {

time=d.timeIntervalSince(aDate)

}

let days= (Int(time ?? 0)) / (3600 * 24)returndays

}

func sunRiset(_ day:Int,long longitude:Double, lat:Double ,altit:Double, limb upper_limb:Int, trise:Double, tset:Double)->Int{

var altit=altit

var d= 0.0/*Days since 2000 Jan 0.0 (negative before)*/

//以歷元2000.0起算的日數(shù)。

var sradius = 0.0 /*Sun's apparent radius*/

//太陽視半徑,約16分(受日地距離、大氣折射等諸多影響)

var t= 0.0 /*Diurnal arc*/

//周日弧,太陽一天在天上走過的弧長。

var tsouth= 0.0 /*Time when Sun is at south*/var sidtime= 0.0 /*Local sidereal time*/

//當(dāng)?shù)睾阈菚r,即地球的真實(shí)自轉(zhuǎn)周期。比平均太陽日(日常時間)長3分56秒。

var rc= 0; /*Return cde from function - usually 0*/

/*Compute d of 12h local mean solar time*/d= Double(day)/*Days_since_2000_Jan_0(date)*/ + 0.5 - longitude / 360.0;//計(jì)算觀測地當(dāng)日中午時刻對應(yīng)2000.0起算的日數(shù)。

/*Compute local sideral time of this moment*/sidtime= self.revolution(self.GMST0(d) + 180.0 +longitude)//計(jì)算同時刻的當(dāng)?shù)睾阈菚r(以角度為單位)。以格林尼治為基準(zhǔn),用經(jīng)度差校正。

/*Compute Sun's RA + Decl at this moment*/self.Sun_RA_dec(d, ra:self.sRA, dec:self.sdec, r:self.sr);//Sun_RA_dec(d, sRA,sdec,sr);//計(jì)算同時刻太陽赤經(jīng)赤緯。

/*Compute time when Sun is at south - in hours UT*/tsouth= 12.0 - self.rev180(sidtime - self.sRA) / 15.0;//tsouth = 12.0 - Rev180(sidtime - sRA) / 15.0;//計(jì)算太陽日的正午時刻,以世界時(格林尼治平太陽時)的小時計(jì)。

/*Compute the Sun's apparent radius, degrees*/sradius= 0.2666 /self.sr;//太陽視半徑。0.2666是一天文單位處的太陽視半徑(角度)。

/*Do correction to upper limb, if necessary*/

if upper_limb != 0{

altit-=sradius;//如果要用上邊緣,就要扣除一個視半徑。

}/*Compute the diurnal arc that the Sun traverses to reach*/

//計(jì)算周日弧。直接利用球面三角公式。如果碰到極晝極夜問題,同前處理。

/*the specified altitide altit:*/var cost:Double= 0cost= (self.sind(altit) - self.sind(lat)*self.sind(self.sdec))/(self.cosd(lat) *self.cosd(self.sdec));//cost = (Sind(altit) - Sind(lat) * Sind(sdec)) ///(Cosd(lat) * Cosd(sdec));

if (cost >= 1.0)

{

rc= -1;

t= 0.0;

}else{if (cost <= -1.0)

{

rc= +1;

t= 12.0; /*Sun always above altit*/}else{//t = Acosd(cost) / 15.0; /* The diurnal arc, hours */

t = self.acosd(cost) / 15.0;

}

}/*Store rise and set times - in hours UT*/self.start= tsouth -t;

self.end= tsouth +t;returnrc;

}

func Sun_RA_dec(_ d: Double, ra RA: Double, dec: Double, r: Double) {

var obl_ecl: Double= 0var x: Double= 0var y: Double= 0var z: Double= 0sunpos(d, lon: lon, r: r)//計(jì)算太陽的黃道坐標(biāo)。

x = sr *cosd(lon)

y= sr *sind(lon)//計(jì)算太陽的直角坐標(biāo)。

obl_ecl = 23.4393 - 3.563E-7 *d//黃赤交角,同前。

z = y *sind(obl_ecl)

y= y *cosd(obl_ecl)//把太陽的黃道坐標(biāo)轉(zhuǎn)換成赤道坐標(biāo)(暫改用直角坐標(biāo))。

sRA =atan2d(y, x: x)

sdec= atan2d(z, x: sqrt(x * x + y *y))//最后轉(zhuǎn)成赤道坐標(biāo)。顯然太陽的位置是由黃道坐標(biāo)方便地直接確定的,但必須轉(zhuǎn)換到赤//道坐標(biāo)里才能結(jié)合地球的自轉(zhuǎn)確定我們需要的白晝長度。

}

func sunpos(_ d: Double, lon: Double, r: Double) {

var lon=lon

var M: Double= 0var w: Double= 0var e: Double= 0var E: Double= 0var x: Double= 0var y: Double= 0var v: Double= 0 //真近點(diǎn)角,太陽在任意時刻的真實(shí)近點(diǎn)角。

M= revolution(356.0470 + 0.9856002585 *d)//自變量的組成:2000.0時刻太陽黃經(jīng)為356.0470度,此后每天約推進(jìn)一度(360度/365天

w = 282.9404 + 4.70935E-5 * d //近日點(diǎn)的平均黃經(jīng)。

e= 0.016709 - 1.151E-9 * d //地球公轉(zhuǎn)橢圓軌道離心率的時間演化。以上公式和黃赤交角公式一樣,不必深究。

E= M + e * Double(Radge) * sind(M) * (1.0 + e *cosd(M))

x= cosd(E) -e

y= sqrt(1.0 - e * e) *sind(E)

sr= sqrt(x * x + y *y)

v=atan2d(y, x: x)

lon= v +w

self.lon=lonif lon >= 360.0{

lon-= 360.0self.lon=lon

}

}

func revolution(_ x: Double)->Double {return x - 360.0 * floor(x *Double(Inv360))

}

func rev180(_ x: Double)->Double {return x - 360.0 * floor(x * Double(Inv360) + 0.5)

}

func GMST0(_ d: Double)->Double {

var sidtim0: Double

sidtim0= revolution((180.0 + 356.0470 + 282.9404) + (0.9856002585 + 4.70935E-5) *d)returnsidtim0

}

func sind(_ x: Double)->Double {return sin(x *Double(Degrad))

}

func cosd(_ x: Double)->Double {return cos(x *Double(Degrad))

}

func acosd(_ x: Double)->Double {return Double(Radge *acos(x))

}

func atan2d(_ y: Double, x: Double)->Double {return Double(Radge *atan2(y, x))

}

}

總結(jié)

以上是生活随笔為你收集整理的4字节 经纬度_Swift4 经纬度计算日出日落时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。