『壹』 利用日期、經緯度求日出日落時間 c語言程序代碼

#definePI3.1415926

#include<math.h>

#include<iostream>

usingnamespacestd;


intdays_of_month_1[]={31,28,31,30,31,30,31,31,30,31,30,31};

intdays_of_month_2[]={31,29,31,30,31,30,31,31,30,31,30,31};

longdoubleh=-0.833;

//定義全局變數


voidinput_date(intc[]){

inti;

cout<<"Enterthedate(form:20090310):"<<endl;

for(i=0;i<3;i++){

cin>>c[i];

}

}

//輸入日期


voidinput_glat(intc[]){

inti;

cout<<"Enterthedegreeoflatitude(range:0°-60°,form:404040(means40°40′40″)):"<<endl;

for(i=0;i<3;i++){

cin>>c[i];

}

}

//輸入緯度


voidinput_glong(intc[]){

inti;

cout<<"Enterthedegreeoflongitude(westisnegativ,form:404040(means40°40′40″)):"<<endl;

for(i=0;i<3;i++){

cin>>c[i];

}

}

//輸入經度


intleap_year(intyear){

if(((year%400==0)||(year%100!=0)&&(year%4==0)))return1;

elsereturn0;

}

//判斷是否為閏年:若為閏年,返回1;若非閏年,返回0


intdays(intyear,intmonth,intdate){

inti,a=0;

for(i=2000;i<year;i++){

if(leap_year(i))a=a+366;

elsea=a+365;

}

if(leap_year(year)){

for(i=0;i<month-1;i++){

a=a+days_of_month_2[i];

}

}

else{

for(i=0;i<month-1;i++){

a=a+days_of_month_1[i];

}

}

a=a+date;

returna;

}

//求從格林威治時間公元2000年1月1日到計算日天數days


longdoublet_century(intdays,longdoubleUTo){

return((longdouble)days+UTo/360)/36525;

}

//求格林威治時間公元2000年1月1日到計算日的世紀數t


longdoubleL_sun(longdoublet_century){

return(280.460+36000.770*t_century);

}

//求太陽的平黃徑


longdoubleG_sun(longdoublet_century){

return(357.528+35999.050*t_century);

}

//求太陽的平近點角


longdoubleecliptic_longitude(longdoubleL_sun,longdoubleG_sun){

return(L_sun+1.915*sin(G_sun*PI/180)+0.02*sin(2*G_sun*PI/180));

}

//求黃道經度


longdoubleearth_tilt(longdoublet_century){

return(23.4393-0.0130*t_century);

}

//求地球傾角


longdoublesun_deviation(longdoubleearth_tilt,longdoubleecliptic_longitude){

return(180/PI*asin(sin(PI/180*earth_tilt)*sin(PI/180*ecliptic_longitude)));

}

//求太陽偏差


longdoubleGHA(longdoubleUTo,longdoubleG_sun,longdoubleecliptic_longitude){

return(UTo-180-1.915*sin(G_sun*PI/180)-0.02*sin(2*G_sun*PI/180)+2.466*sin(2*ecliptic_longitude*PI/180)-0.053*sin(4*ecliptic_longitude*PI/180));

}

//求格林威治時間的太陽時間角GHA


longdoublee(longdoubleh,longdoubleglat,longdoublesun_deviation){

return180/PI*acos((sin(h*PI/180)-sin(glat*PI/180)*sin(sun_deviation*PI/180))/(cos(glat*PI/180)*cos(sun_deviation*PI/180)));

}

//求修正值e


longdoubleUT_rise(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){

return(UTo-(GHA+glong+e));

}

//求日出時間


longdoubleUT_set(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){

return(UTo-(GHA+glong-e));

}

//求日落時間


longdoubleresult_rise(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){

longdoubled;

if(UT>=UTo)d=UT-UTo;

elsed=UTo-UT;

if(d>=0.1){

UTo=UT;

UT=UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));

result_rise(UT,UTo,glong,glat,year,month,date);

}

returnUT;

}

//判斷並返回結果(日出)


longdoubleresult_set(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){

longdoubled;

if(UT>=UTo)d=UT-UTo;

elsed=UTo-UT;

if(d>=0.1){

UTo=UT;

UT=UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));

result_set(UT,UTo,glong,glat,year,month,date);

}

returnUT;

}

//判斷並返回結果(日落)


intZone(longdoubleglong){

if(glong>=0)return(int)((int)(glong/15.0)+1);

elsereturn(int)((int)(glong/15.0)-1);

}

//求時區


voidoutput(longdoublerise,longdoubleset,longdoubleglong){

if((int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<10)

cout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":0"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";

elsecout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";

if((int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<10)

cout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";

elsecout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";

}

//列印結果intmain(){

longdoubleUTo=180.0;

intyear,month,date;

longdoubleglat,glong;

intc[3];

input_date(c);

year=c[0];

month=c[1];

date=c[2];

input_glat(c);

glat=c[0]+c[1]/60+c[2]/3600;

input_glong(c);

glong=c[0]+c[1]/60+c[2]/3600;

longdoublerise,set;

rise=result_rise(UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);

set=result_set(UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);

output(rise,set,glong);

system("pause");

return0;

}

『貳』 C語言知道經緯度求兩地距離的題目,求高手指點哪裡錯了,對了再加分

最後的計算s的公式有問題,因為反餘弦函數y=arccosx中,y的取值范圍只能是-π/2 ≤ y ≤ π/2,而地球上兩點間的夾角明顯在0到180°之間,所以這個地方你還應該加上角度判斷語句,另外你的R的單位是km,最後的結果頁應該是km。

『叄』 求c點的經緯度,求講解

70°s,45°E

『肆』 請問點C的經緯度是多少

北緯22.5度,西經30度

『伍』 C語言中怎麼表示經緯度呢

提供一思路,僅參考:
參照坐標系點的表示法
a(x,y)

『陸』 C() D() 經緯度

c:165w,40N
d:150E,60N

『柒』 C語言實現經緯度的轉換

辦法很多,三維字元數組,指針字元數組都可以,分別保存字元串到數組元素,最後以%s輸出即可。
我來寫個最簡單的

#include "stdafx.h"
#include "stdlib.h"
#include "string.h"

void explain_NS(char * str)
{
char tmp_ca[30] = "";
if(str[0] == 'N')
strcpy(tmp_ca,"北緯");
else
strcpy(tmp_ca,"南緯");
char *p = tmp_ca;
while(*p) p++;
strncpy(p, str+1, 2);
p += 2;
*p = 176;
p ++;
strncpy(p,str+3,2);
p += 2;
*p = 39;
p++;
strncpy(p, str+6,5);
p += 5;
*p = 34;
printf("%s\n",tmp_ca);
}
void explain_EW(char * str)
{
char tmp_ca[30] = "";
if(str[0] == 'E')
strcpy(tmp_ca,"東經");
else
strcpy(tmp_ca,"西經");
char *p = tmp_ca;
while(*p) p++;
strncpy(p, str+1, 3);
p += 3;
*p = 176;
p ++;
strncpy(p,str+4,2);
p += 2;
*p = 39;
p++;
strncpy(p, str+7,5);
p += 5;
*p = 34;
printf("%s\n",tmp_ca);
}
int _tmain(int argc, _TCHAR* argv[])
{
char ca[30] = "N3018.93661";
char cb[30] = "E12022.88281";
explain_NS(ca);
explain_EW(cb);
system("pause");
return 0;
}

『捌』 c語言中計算gps坐標轉經緯度

就是純計算公式,一個公式就可以解決。具體邏輯如下。

一般從GPS得到的數據是經緯度。經緯度有多種表示方法。
1.) ddd.ddddd, 度 . 度的十進制小數部分(5位)例如:31.12035º
2.) ddd.mm.mmm,度 . 分 . 分的十進制小數部分(3位)例如 31º10.335′
3.) ddd.mm.ss, 度 . 分 . 秒 例如 31º12』42″
地球上任何一個固定的點都可以用確定的經緯度表示出來。
關於經緯度坐標轉換的方法
一、十進制轉換成經緯度
把經緯度轉換成十進制的方法很簡單
如下就可以了
Decimal Degrees = Degrees + minutes/60 + seconds/3600
例:57°55』56.6″ =57+55/60+56.6/3600=57.9323888888888
114°65』24.6″=114+65/60+24.6/3600=結果自己算!
如把經緯度 (longitude,latitude) (205.395583333332,57.9323888888888)
轉換據成坐標(Degrees,minutes,seconds)(205°23』44.1″,57°55』56.6″)。
步驟如下:
1, 直接讀取」度」:205
2,(205.395583333332-205)*60=23.734999999920 得到」分」:23
3,(23.734999999920-23)*60=44.099999995200 得到」秒」:44.1
採用同樣的方法可以得到緯度坐標:57°55』56.6″

『玖』 GPS模塊獲取的數據轉換成經緯度(度分秒的格式),C語言

3559.10468,N,12009.46619,E
N/S(北緯或南緯):北緯35 度59.10468 分;
E/W(東經或西經):東經120 度9.46619 分;
緯度(格式ddmm.mmmm:即dd 度,mm.mmmm 分);
經度(格式dddmm.mmmm:即ddd 度,mm.mmmm 分);
list和字元串操作就不寫了吧。