Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.astronomy.ru/forum/index.php/topic,18236.0.html
Дата изменения: Sun Apr 10 04:48:06 2016
Дата индексирования: Sun Apr 10 04:48:06 2016
Кодировка: Windows-1251

Поисковые слова: arp 220
Функция расчета лунных дней - Астрономия и компьютеры

A A A A Автор Тема: Функция расчета лунных дней  (Прочитано 1669 раз)

0 Пользователей и 1 Гость просматривают эту тему.

mobscene

  • Гость
Перевел http://avy.ru/programs/moonday/md.js на делфи. Но точность ее помойму хромает. Помогите разобраться, может что подправить надо?

unit moonday;

interface

uses
 SysUtils, Math;

const
 milenium:   Array[0..6]  of extended = (0.0, 13.9, 27.7, 12.1, 25.9, 10.3, 24.2);
 century:    Array[0..9] of extended = (0.0, 4.3, 8.7, 13.0, 17.4, 21.7, 26.0, 0.8, 5.2, 9.5);
 ten:        Array[0..9] of extended = (0.0, 9.3, 18.6, 27.9, 7.6, 16.9, 26.2, 6.0, 15.3, 24.6);
 year:       Array[0..9] of extended = (0.0, 18.6, 7.8, 26.4, 15.5, 4.6, 23.3, 12.4, 1.5, 20.2);
 month_new:  Array[0..11] of extended = (13.4, 11.9, 24.2, 22.6, 22.0, 20.6, 20.0, 18.4, 17.0, 16.6, 15.1, 14.8);
 month_full: Array[0..11] of extended = (28.2, 26.7, 9.5, 7.9, 7.3, 5.8, 5.3, 3.6, 2.2, 1.9, 0.3, 0.0);

function GetDate(ypos1,ypos2,ypos3,ypos4,month,tmoon: integer): extended;
function MoonDayIs(ypos1,ypos2,ypos3,ypos4,month,day,hour: integer): extended;

implementation

function GetDate(ypos1,ypos2,ypos3,ypos4,month,tmoon: integer): extended;
var
 x: extended;
begin
result:=0;
 if ((month=1) or (month=2)) then begin
   ypos4:=ypos4-1;
  if (ypos4<0) then begin
     ypos4:=9;
   ypos3:=ypos3-1;
  end;
  if (ypos3<0) then begin
   ypos3:=9;
   ypos2:=ypos2-1;
  end;
  if (ypos2<0)then begin
   ypos2:=9;
   ypos1:=ypos1-1;
  end;
 end;

 if ((ypos1>=0) and (ypos1<=6)) then result:=result+milenium[ypos1];
 if ((ypos2>=0) and (ypos2<=9)) then result:=result+century[ypos2];
 if ((ypos3>=0) and (ypos3<=9)) then result:=result+ten[ypos3];
 if ((ypos4>=0) and (ypos4<=9)) then result:=result+year[ypos4];

 if (tmoon=1) then
   result:=result+month_new[month-1]
 else
  result:=result+month_full[month-1];

x:=ypos3*10+ypos4;
x:=x/4;
 if (x=1) then result:=result+0.2;
 if (x=2) then result:=result+0.5;
 if (x=3) then result:=result+0.8;

x:=ypos1*10+Math.floor(ypos2);
x:=round(0.75*x-1.625);
result:=result+x;
 if (result>119.1) then result:=result-118.1;
 if (result>89.6)  then result:=result-88.6;
 if (result>60.1)  then result:=result-59.1;
 if (result>30.5)  then result:=result-29.5;

result:=round(result*10)/10;
end;

function MoonDayIs(ypos1,ypos2,ypos3,ypos4,month,day,hour: integer): extended;
var
 nov,dr: extended;
begin
result:=0;
nov:=GetDate(ypos1,ypos2,ypos3,ypos4,month,1);
 if (nov=0) then exit;
dr:=Math.floor(day)+(round(hour/24*10)/10);

result:=dr-nov;
 if (result<0) then result:=result+29.5;

result:=Math.floor(result)+1;
end;

end.

Собственно проблема в том, что сегодня когда через java проверял, скрипт выдал 29 лунный день. Но вот ее аналог на делфи

ShowMessage(FloatToStr(MoonDayIs(2,0,0,6,7,24,17)));
 выдавал значение "30".

Оффлайн anddor

  • ****
  • Сообщений: 378
  • Рейтинг: +1/-0
  • Per aspera ad astra!
Re: Функция расчета лунных дней
« Ответ #1 : 26.07.2006 [22:17:54] »
Может быть, дело в следующем:

Цитировать
result:=Math.floor(result)+1

После округления результата Вы зачем-то добавляете единицу.
Открылась бездна, звезд полна.
Звездам числа нет, бездне - дна...
                                   М.В. Ломоносов

mobscene

  • Гость
Re: Функция расчета лунных дней
« Ответ #2 : 31.08.2006 [15:24:37] »
Попробовал, Убрал единицу. Появился нулевой лунный день ;) Вобщем то функция эта работает, сравнивал ее результаты с результатами zet. Расхождение в пару часов, не более