<p>Here is the page code for <a href="http://sionnagh.com/mtdistcalc.php" rel="nofollow noreferrer" title="my BASIC-to-php implementation">my BASIC-to-php implementation</a> of the algorithms to calculate the  (geocentric) RA &amp; Dec of the Sun for a given date from Jean Meeus' book <em>Astronomical Algorithms</em> as well as calculating the angular distance between two celestial objects.  I can't remember the accuracy of the calculations and I didn't make the corrections for observer lat &amp; long.</p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1" /&gt;
 &lt;base href="sionnagh.com" /&gt;
&lt;title&gt;Mick Todd Distance Calculator&lt;/title&gt;
&lt;STYLE TYPE="text/css"&gt;
&lt;!--
BODY
   {
   font-family:sans-serif;
   }
A:link{color:white}
A:visited{color:yellow}
--&gt;
&lt;/STYLE&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php include("mtheader.php"); ?&gt;
&lt;h1&gt;Mick Todd Distance Calculator&lt;/h1&gt;
&lt;?php 
$earthincl=23.44; //Earth's axial tilt
$sollat=0;

$fdate = $_POST["fdate"];
if ($fdate=="") {
 $fdate=getdate(date("U")-date("Z"));
 $fday=$fdate[mday];
 if (strlen($fday)==1) {$fday="0".$fday;}
 $fmonth=$fdate[mon];
 if (strlen($fmonth)==1) {$fmonth="0".$fmonth;}
 $fyear=$fdate[year];
 //$fdate=$fdate[mday]."/".$fdate[mon]."/".$fdate[year];
 $fdate=$fday."/".$fmonth."/".$fyear;
}
else {
 $fday=substr($fdate,0,2);
 $fmonth=substr($fdate,3,2);
 $fyear=substr($fdate,6,4);
}
$fra1 = $_POST["fra1"];
$fra1 = strtolower($fra1);
if ($fra1&lt;&gt;"") {
  if (strpos($fra1,"h")==0) {
  $frad1=$fra1;
  $fra1=converttohms($fra1);
  }
  else {
    $frad1=converthtod($fra1);
  }
}
$fdec1 = $_POST["fdec1"];
$fdec1 = strtolower($fdec1);
if ($fdec1&lt;&gt;"") {
  if (strpos($fdec1,"d")==0) {
    $fdecd1=$fdec1;
    $fdec1=converttodms($fdec1);
  }
  else {
    $fdecd1=convertdtod($fdec1);
  }
}
$fra2 = $_POST["fra2"];
$fra2 = strtolower($fra2);
if ($fra2&lt;&gt;"") {
  if (strpos($fra2,"h")==0) {
    $frad2=$fra2;
    $fra2=converttohms($fra2);
  }
  else {
    $frad2=converthtod($fra2);
  }
}
$fdec2 = $_POST["fdec2"];
$fdec2 = strtolower($fdec2);
if ($fdec2&lt;&gt;"") {
  if (strpos($fdec2,"d")==0) {
    $fdecd2=$fdec2;
    $fdec2=converttodms($fdec2);
  }
  else {
    $fdecd2=convertdtod($fdec2);
  }
}

function JulianDay ($fday, $fmonth, $fyear, $fUT) {
    $JDpartsign=(100*$fyear+$fmonth-190002.5)/abs(100*$fyear+$fmonth-190002.5);
 $JD = 367*$fyear - floor((7*($fyear+floor(($fmonth+9)/12)))/4) + floor((275*$fmonth)/9) + $fday + 1721013.5 + $fUT/24 - 0.5*$JDpartsign + 0.5;
 return $JD;
}
function converttodms($inval) {
 if ($inval==0) {
   $fdsign=1;
 }
 else {
   $fdsign=$inval/abs($inval);
 }
 $inval=abs($inval);
 $fddeg=floor($inval);
 $remain=($inval-$fddeg)*60;
 $fdmin=floor($remain);
 if (strlen($fdmin)==1) { $fdmin="0".$fdmin; }
 $remain=($remain-$fdmin)*60;
 $fdsec=round($remain*100)/100;
 if (strpos($fdsec,".")==1) { $fdsec="0".$fdsec; }
 $fddeg=$fdsign*$fddeg;
 $fdms=$fddeg."d".$fdmin."m".$fdsec."s";

    return $fdms;
}
function converttohms($inval) {
    $inval=$inval/15;
    $fddeg=floor($inval);
    $remain=($inval-$fddeg)*60;
 $fdmin=floor($remain);
 if (strlen($fdmin)==1) { $fdmin="0".$fdmin; }
    $remain=($remain-$fdmin)*60;
 $fdsec=round($remain*100)/100;
 if (strpos($fdsec,".")==1) { $fdsec="0".$fdsec; }
    $fdms=$fddeg."h".$fdmin."m".$fdsec."s";

    return $fdms;
}
function converthtod($inval) {
  $posh=strpos($inval,"h");
  $posm=strpos($inval,"m");
  $poss=strpos($inval,"s");
  $temph=substr($inval,0,$posh);
  if ($posm) {
    $tempm=substr($inval,$posh+1,$posm-($posh+1));
  }
  if ($poss) {
    $temps=substr($inval,$posm+1,$poss-($posm+1));
  }

  $fdms=($temph+$tempm/60+$temps/3600)*15;

  return $fdms;
}
function convertdtod($inval) {
  $posd=strpos($inval,"d");
  $posm=strpos($inval,"m");
  $poss=strpos($inval,"s");
  $tempd=substr($inval,0,$posd);
  if ($posm) {
    $tempm=substr($inval,$posd+1,$posm-($posd+1));
  }
  if ($poss) {
    $temps=substr($inval,$posm+1,$poss-($posm+1));
  }
  $fdms=$tempd+$tempm/60+$temps/3600;

  return $fdms;
}

function SolarCoords($fday, $fmonth, $fyear, $fUT) {
//Julian Day of 1991/ 5/19 at 13 UT         JD = 2448396.04167
//Julian day of 2000/01/01 at 12 UT         JD = 2451545.0
//number of Julian days since 2000/01/01 at 12 UT               -3148.95833
//number of Julian centuries since 2000/01/01 at 12 UT  T = - 3148.95833/36525
//used by the algorithm for L                                                           = 0.086213780

    $k = 2*pi()/360;
  $T = (JulianDay($fday, $fmonth, $fyear, $fUT)-2451545.0)/36525;
    //echo "\$T: ".$T."&lt;br /&gt;";
 //mean anomaly, degree
 $M = 357.52910 + 35999.05030*$T - 0.0001559*$T*$T - 0.00000048*$T*$T*$T;
    //echo "\$M: ".$M."&lt;br /&gt;";

    // mean longitude, degree
    $L0 = 280.46645 + 36000.76983*$T + 0.0003032*$T*$T;
    //echo "\$L0: ".$L0."&lt;br /&gt;";

    $DL = (1.914600 - 0.004817*$T - 0.000014*$T*$T)*sin($k*$M) + (0.019993 - 0.000101*$T)*sin($k*2*$M) + 0.000290*sin($k*3*$M);
 //echo "\$DL: ".$DL."&lt;br /&gt;";

    // true longitude, degree
    $L = $L0 + $DL;
 if (abs($L)&gt;360) {
        $divsign=($L/360)/abs($L/360);
  $div=floor(abs($L/360));
  $L=$L-$divsign*$div*360;
  if ($L&lt;0) { $L=$L+360; }
    }
    $L=round($L*10000)/10000;

    return $L;

}

?&gt;
&lt;script type="text/javascript"&gt;
    &lt;!--
    function settoday() {
        var d=new Date();
        dday=d.getDate();
        if (dday&lt;10) { dday="0" + dday; }
        dmonth=d.getMonth()+1;
        if (dmonth&lt;10) { dmonth="0" + dmonth; }
        dyear=d.getFullYear();

        ddate= dday + "/" + dmonth + "/" + dyear;

        return ddate;

    }

    //--&gt;
&lt;/script&gt;
&lt;form METHOD="POST" ACTION="mtdistcalc.php" name="mtdistcalc"&gt;


&lt;p&gt;Date &lt;input type="text" name="fdate" id="fdate" size=10 value="&lt;?php echo $fdate; ?&gt;"&gt; &lt;input type="button" value="Now" onclick="fdate.value=settoday();"&gt;&lt;/p&gt;
&lt;p&gt;Object coordinates (#1) RA &lt;input type="text" name="fra1" id="fra1" size=15 value="&lt;?php echo $fra1; ?&gt;"&gt;  Decl &lt;input type="text" name="fdec1" id="fdec1" size=15 value="&lt;?php echo $fdec1; ?&gt;"&gt;&lt;/p&gt;
&lt;p&gt;Object coordinates (#2) RA &lt;input type="text" name="fra2" id="fra2" size=15 value="&lt;?php echo $fra2; ?&gt;"&gt;  Decl &lt;input type="text" name="fdec2" id="fdec2" size=15 value="&lt;?php echo $fdec2; ?&gt;"&gt;&lt;/p&gt;
  &lt;p&gt;&lt;input TYPE=SUBMIT VALUE="Calculate distances"&gt;&lt;/p&gt;


&lt;/form&gt;
&lt;?php
echo "&lt;table&gt;&lt;tr&gt;&lt;td&gt;Date:&lt;/td&gt;&lt;td&gt;".$fday."/".$fmonth."/".$fyear." "."0000UT&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;tr&gt;&lt;td&gt;Julian Day: &lt;/td&gt;&lt;td&gt;".JulianDay($fday,$fmonth,$fyear,"0")."&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;tr&gt;&lt;td&gt;Ecliptic latitude of the Sun: &lt;/td&gt;&lt;td&gt;".$sollat."&amp;deg; (assumed)&lt;/td&gt;&lt;/tr&gt;";
$sollong = SolarCoords($fday,$fmonth,$fyear,"0");
echo "&lt;tr&gt;&lt;td&gt;Ecliptic longitude of the Sun: &lt;/td&gt;&lt;td&gt;".$sollong."&amp;deg; (".converttodms($sollong).")&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;tr&gt;&lt;td&gt;Earth's axial inclination: &lt;/td&gt;&lt;td&gt;".$earthincl."&amp;deg;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;";

//echo "\$feclong ".$feclong."&lt;br /&gt;&lt;br /&gt;";

$deltaSol = round(asin(sin($sollat*M_PI/180)*cos($earthincl*M_PI/180) + cos($sollat*M_PI/180)*sin($earthincl*M_PI/180)*sin($sollong*M_PI/180))*180/M_PI*10000)/10000;
$alphaSol = round(acos(cos($sollong*M_PI/180)*cos($sollat*M_PI/180) / cos($deltaSol*M_PI/180))*180/M_PI*10000)/10000;
if ($sollong&gt;180) {
 $alphaSol = 360-$alphaSol;
}
echo "&lt;table&gt;&lt;tr&gt;&lt;td colspan=2&gt;Sol&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;RA: &lt;/td&gt;&lt;td&gt;".$alphaSol."&amp;deg; (".converttohms($alphaSol).")&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Dec:&lt;/td&gt;&lt;td&gt;".$deltaSol."&amp;deg; (".converttodms($deltaSol).")&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;";

//spherical angular distance
//cos(theta) = sin(delta_a) sin(delta_b) + cos(delta_a) cos(delta_b) cos(alpha_a-alpha_b)
if ($fra1&lt;&gt;"" AND $fdec1&lt;&gt;"") {
  $theta1 = round(acos(sin($deltaSol*M_PI/180)*sin($fdecd1*M_PI/180) + cos($deltaSol*M_PI/180)*cos($fdecd1*M_PI/180)*cos(($alphaSol-$frad1)*M_PI/180))*180/M_PI*1000)/1000;
}
if ($fra2&lt;&gt;"" AND $fdec2&lt;&gt;"") {
  $theta2 = round(acos(sin($deltaSol*M_PI/180)*sin($fdecd2*M_PI/180) + cos($deltaSol*M_PI/180)*cos($fdecd2*M_PI/180)*cos(($alphaSol-$frad2)*M_PI/180))*180/M_PI*1000)/1000;
}

if ($fra1&lt;&gt;"" AND $fdec1&lt;&gt;"" AND $fra2&lt;&gt;"" AND $fdec2&lt;&gt;"") {
  $theta3 = round(acos(sin($fdecd1*M_PI/180)*sin($fdecd2*M_PI/180) + cos($fdecd1*M_PI/180)*cos($fdecd2*M_PI/180)*cos(($frad1-$frad2)*M_PI/180))*180/M_PI*1000)/1000;
  echo "&lt;p&gt;&lt;font color=\"#0000FF\"&gt;Angular distance between Object #1 and Object #2 is: ".$theta3."&amp;deg;&lt;/font&gt;&lt;/p&gt;";
}

if (($fra1&lt;&gt;"" and $fdec1&lt;&gt;"") or ($fra2&lt;&gt;"" and $fdec2&lt;&gt;"")) {
  echo "&lt;table&gt;&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td align=center&gt;&lt;b&gt;RA&lt;/b&gt;&lt;/td&gt;&lt;td align=center&gt;&lt;b&gt;Dec&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Solar elong.&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;";
}
if ($fra1&lt;&gt;"" AND $fdec1&lt;&gt;"") {
  echo "&lt;tr&gt;&lt;td&gt;Object #1:&lt;/td&gt;&lt;td&gt;&lt;font color=Maroon&gt;".$fra1."&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color=Maroon&gt;".$fdec1."&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font color=Maroon&gt;".$theta1."&amp;deg;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;";
}
if ($fra2&lt;&gt;"" AND $fdec2&lt;&gt;"") {
  echo "&lt;tr&gt;&lt;td&gt;Object #2:&lt;/td&gt;&lt;td&gt;".$fra2."&lt;/td&gt;&lt;td&gt;".$fdec2."&lt;/td&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;".$theta2."&amp;deg;&lt;/td&gt;&lt;/tr&gt;";
}


?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

CC BY-SA 4.0
2018-07-04T09:59:57.473Z
How would you compute the transit/solar noon from the RA and dec?
serv-inc
CC BY-SA 4.0
2018-07-04T10:08:29.020Z
Local sidereal time is the RA of a star on your meridian and is offset from UT based on your longitude and the date. When your LST matches the Sun's RA then the Sun is on the meridian. (You don't need the Dec here.)
Mick
CC BY-SA 4.0
2018-07-04T10:18:31.523Z
So the LST at longitude (and latitude?) needs to be computed and matched to the RA (of 103.0508°). That is the time of the solar noon? Sounds good.
serv-inc
CC BY-SA 4.0
2018-07-04T10:25:21.270Z
The LST is just longitude-based (as is RA), so yes, when LST and RA of the Sun match then that is solar noon. The RA of the Sun will be slightly different at 8 am local time than at local noon (12 pm) and also at solar noon.
Mick
CC BY-SA 4.0
2018-07-04T11:42:55.953Z
Seems like the topic is quite deep. Would you recommend any primers into astronomy? (Or would that be all? In which case: is is ok'ish to just use the RA from you without any time adjustment?)
serv-inc
CC BY-SA 4.0
2018-07-04T11:58:34.503Z
There are so many aspects besides "looking at stuff in the sky" that I hesitate to suggest anything, but _Atlas of the Universe_ by Sir Patrick Moore is one of the first books that I read. And if that RA calculation works for you, then by all means use it.
Mick
CC BY-SA 4.0
2018-07-06T12:17:39.813Z
In the end, the modified Java versions seems easier to use. Still, the glimpse into the why and how was helpful.
serv-inc
CC BY-SA 4.0
2018-07-04T09:12:07.560Z
2018-07-04T09:12:07.560Z
Mick
<p>As detailed in <a href="https://physics.stackexchange.com/questions/41450/is-there-a-simple-accurate-formula-for-calculating-transit-times-from-rise-and">https://physics.stackexchange.com/questions/41450/is-there-a-simple-accurate-formula-for-calculating-transit-times-from-rise-and</a>, the sunrise, and set times can accurately be used to compute the sun's transit. Yet, in some cases, these do not exist, e.g. in Finland in the summer.</p>

<p>Is there an easier and/or more general way to compute the transit time (and only the transit time) given the UTC and observer position (latitude, longitude, height). </p>

<p><sub>The library at <a href="http://www.jstott.me.uk/jsuntimes" rel="nofollow noreferrer">http://www.jstott.me.uk/jsuntimes</a> gives sunrise and sunset, but not the transit time. <code>find_transit</code> at <code>riset_cir.c</code> in <a href="https://github.com/brandon-rhodes/pyephem/tree/master/libastro-3.7.7" rel="nofollow noreferrer">https://github.com/brandon-rhodes/pyephem/tree/master/libastro-3.7.7</a> might do this, but seems too general and complicated.</sub></p>

CC BY-SA 4.0
2018-07-04T07:44:25.500Z
How close do you want it? The transit time can be approximated as the arithmetic mean of the rise and set times. And what does not exist? Sunrise and -set times? You already linked to a site for obtaining those.
Mick
CC BY-SA 4.0
2018-07-04T08:25:23.507Z
@Mick: the sun does not always set everywhere, whereas the transit always exists.
serv-inc
CC BY-SA 4.0
2018-07-04T08:29:20.327Z
Do you mean near the poles? Then you will need to take a non-trivial approach and calculate it from the RA of the Sun as mentioned by barrycarter.
Mick
CC BY-SA 4.0
2018-07-04T08:31:33.447Z
@Mick: yes, even e.g.  in northern sweden the sun does not always rise and/or set. Do you have any pointers on how to do this (accuracy might be off by seconds, but  should not be off by minutes)?
serv-inc
CC BY-SA 4.0
2018-07-04T08:51:25.730Z
I did some work some years ago where I made a page on the web where I calculated the (geocentric) RA & Dec of the Sun for a given date using the algorithms in Jean Meeus' book _Astronomical Algorithms_. I can't remember the accuracy of the calculations and I didn't make the corrections for observer lat & long. The web page is still on my server at http://sionnagh.com/mtdistcalc.php, and I am happy to share the BASIC-to-php converted code behind it if that would help.
Mick
CC BY-SA 4.0
2018-07-04T08:56:36.780Z
@Mick: yes, that would help
serv-inc
<the-sun><planetary-transits>
How to compute the sun's (upper) transit
serv-inc
# How to compute the sun's (upper) transit

(Asked by: username_0 on 2018-07-03)

As detailed in <https://physics.stackexchange.com/questions/41450/is-there-a-simple-accurate-formula-for-calculating-transit-times-from-rise-and>, the sunrise, and set times can accurately be used to compute the sun's transit. Yet, in some cases, these do not exist, e.g. in Finland in the summer.

Is there an easier and/or more general way to compute the transit time (and only the transit time) given the UTC and observer position (latitude, longitude, height).

The library at <http://www.jstott.me.uk/jsuntimes> gives sunrise and sunset, but not the transit time. `find_transit` at `riset_cir.c` in <https://github.com/brandon-rhodes/pyephem/tree/master/libastro-3.7.7> might do this, but seems too general and complicated.

**Tags:** the-sun, planetary-transits

> **Comments:**
> **username_1**: How close do you want it? The transit time can be approximated as the arithmetic mean of the rise and set times. And what does not exist? Sunrise and -set times? You already linked to a site for obtaining those.  
> **username_0**: @username_1: the sun does not always set everywhere, whereas the transit always exists.  
> **username_1**: Do you mean near the poles? Then you will need to take a non-trivial approach and calculate it from the RA of the Sun as mentioned by barrycarter.  
> **username_0**: @username_1: yes, even e.g.  in northern sweden the sun does not always rise and/or set. Do you have any pointers on how to do this (accuracy might be off by seconds, but  should not be off by minutes)?  
> **username_1**: I did some work some years ago where I made a page on the web where I calculated the (geocentric) RA & Dec of the Sun for a given date using the algorithms in Jean Meeus' book _Astronomical Algorithms_. I can't remember the accuracy of the calculations and I didn't make the corrections for observer lat & long. The web page is still on my server at http://sionnagh.com/mtdistcalc.php, and I am happy to share the BASIC-to-php converted code behind it if that would help.  
> **username_0**: @username_1: yes, that would help  

---

## 1 answers

### Answer by username_1 on 2018-07-04. Score: 1 | Accepted answer

Here is the page code for my BASIC-to-php implementation of the algorithms to calculate the  (geocentric) RA & Dec of the Sun for a given date from Jean Meeus' book Astronomical Algorithms as well as calculating the angular distance between two celestial objects.  I can't remember the accuracy of the calculations and I didn't make the corrections for observer lat & long.




 
username_1 Todd Distance Calculator




username_1 Todd Distance Calculator
"") {
  if (strpos($fra1,"h")==0) {
  $frad1=$fra1;
  $fra1=converttohms($fra1);
  }
  else {
    $frad1=converthtod($fra1);
  }
}
$fdec1 = $_POST["fdec1"];
$fdec1 = strtolower($fdec1);
if ($fdec1<>"") {
  if (strpos($fdec1,"d")==0) {
    $fdecd1=$fdec1;
    $fdec1=converttodms($fdec1);
  }
  else {
    $fdecd1=convertdtod($fdec1);
  }
}
$fra2 = $_POST["fra2"];
$fra2 = strtolower($fra2);
if ($fra2<>"") {
  if (strpos($fra2,"h")==0) {
    $frad2=$fra2;
    $fra2=converttohms($fra2);
  }
  else {
    $frad2=converthtod($fra2);
  }
}
$fdec2 = $_POST["fdec2"];
$fdec2 = strtolower($fdec2);
if ($fdec2<>"") {
  if (strpos($fdec2,"d")==0) {
    $fdecd2=$fdec2;
    $fdec2=converttodms($fdec2);
  }
  else {
    $fdecd2=convertdtod($fdec2);
  }
}

function JulianDay ($fday, $fmonth, $fyear, $fUT) {
    $JDpartsign=(100*$fyear+$fmonth-190002.5)/abs(100*$fyear+$fmonth-190002.5);
 $JD = 367*$fyear - floor((7*($fyear+floor(($fmonth+9)/12)))/4) + floor((275*$fmonth)/9) + $fday + 1721013.5 + $fUT/24 - 0.5*$JDpartsign + 0.5;
 return $JD;
}
function converttodms($inval) {
 if ($inval==0) {
   $fdsign=1;
 }
 else {
   $fdsign=$inval/abs($inval);
 }
 $inval=abs($inval);
 $fddeg=floor($inval);
 $remain=($inval-$fddeg)*60;
 $fdmin=floor($remain);
 if (strlen($fdmin)==1) { $fdmin="0".$fdmin; }
 $remain=($remain-$fdmin)*60;
 $fdsec=round($remain*100)/100;
 if (strpos($fdsec,".")==1) { $fdsec="0".$fdsec; }
 $fddeg=$fdsign*$fddeg;
 $fdms=$fddeg."d".$fdmin."m".$fdsec."s";

    return $fdms;
}
function converttohms($inval) {
    $inval=$inval/15;
    $fddeg=floor($inval);
    $remain=($inval-$fddeg)*60;
 $fdmin=floor($remain);
 if (strlen($fdmin)==1) { $fdmin="0".$fdmin; }
    $remain=($remain-$fdmin)*60;
 $fdsec=round($remain*100)/100;
 if (strpos($fdsec,".")==1) { $fdsec="0".$fdsec; }
    $fdms=$fddeg."h".$fdmin."m".$fdsec."s";

    return $fdms;
}
function converthtod($inval) {
  $posh=strpos($inval,"h");
  $posm=strpos($inval,"m");
  $poss=strpos($inval,"s");
  $temph=substr($inval,0,$posh);
  if ($posm) {
    $tempm=substr($inval,$posh+1,$posm-($posh+1));
  }
  if ($poss) {
    $temps=substr($inval,$posm+1,$poss-($posm+1));
  }

  $fdms=($temph+$tempm/60+$temps/3600)*15;

  return $fdms;
}
function convertdtod($inval) {
  $posd=strpos($inval,"d");
  $posm=strpos($inval,"m");
  $poss=strpos($inval,"s");
  $tempd=substr($inval,0,$posd);
  if ($posm) {
    $tempm=substr($inval,$posd+1,$posm-($posd+1));
  }
  if ($poss) {
    $temps=substr($inval,$posm+1,$poss-($posm+1));
  }
  $fdms=$tempd+$tempm/60+$temps/3600;

  return $fdms;
}

function SolarCoords($fday, $fmonth, $fyear, $fUT) {
//Julian Day of 1991/ 5/19 at 13 UT         JD = 2448396.04167
//Julian day of 2000/01/01 at 12 UT         JD = 2451545.0
//number of Julian days since 2000/01/01 at 12 UT               -3148.95833
//number of Julian centuries since 2000/01/01 at 12 UT  T = - 3148.95833/36525
//used by the algorithm for L                                                           = 0.086213780

    $k = 2*pi()/360;
  $T = (JulianDay($fday, $fmonth, $fyear, $fUT)-2451545.0)/36525;
    //echo "\$T: ".$T."";
 //mean anomaly, degree
 $M = 357.52910 + 35999.05030*$T - 0.0001559*$T*$T - 0.00000048*$T*$T*$T;
    //echo "\$M: ".$M."";

    // mean longitude, degree
    $L0 = 280.46645 + 36000.76983*$T + 0.0003032*$T*$T;
    //echo "\$L0: ".$L0."";

    $DL = (1.914600 - 0.004817*$T - 0.000014*$T*$T)*sin($k*$M) + (0.019993 - 0.000101*$T)*sin($k*2*$M) + 0.000290*sin($k*3*$M);
 //echo "\$DL: ".$DL."";

    // true longitude, degree
    $L = $L0 + $DL;
 if (abs($L)>360) {
        $divsign=($L/360)/abs($L/360);
  $div=floor(abs($L/360));
  $L=$L-$divsign*$div*360;
  if ($L<0) { $L=$L+360; }
    }
    $L=round($L*10000)/10000;

    return $L;

}

?>




Date  
Object coordinates (#1) RA   Decl 
Object coordinates (#2) RA   Decl 
  



Date:".$fday."/".$fmonth."/".$fyear." "."0000UT";
echo "Julian Day: ".JulianDay($fday,$fmonth,$fyear,"0")."";
echo "Ecliptic latitude of the Sun: ".$sollat."° (assumed)";
$sollong = SolarCoords($fday,$fmonth,$fyear,"0");
echo "Ecliptic longitude of the Sun: ".$sollong."° (".converttodms($sollong).")";
echo "Earth's axial inclination: ".$earthincl."°";

//echo "\$feclong ".$feclong."";

$deltaSol = round(asin(sin($sollat*M_PI/180)*cos($earthincl*M_PI/180) + cos($sollat*M_PI/180)*sin($earthincl*M_PI/180)*sin($sollong*M_PI/180))*180/M_PI*10000)/10000;
$alphaSol = round(acos(cos($sollong*M_PI/180)*cos($sollat*M_PI/180) / cos($deltaSol*M_PI/180))*180/M_PI*10000)/10000;
if ($sollong>180) {
 $alphaSol = 360-$alphaSol;
}
echo "SolRA: ".$alphaSol."° (".converttohms($alphaSol).")Dec:".$deltaSol."° (".converttodms($deltaSol).")";

//spherical angular distance
//cos(theta) = sin(delta_a) sin(delta_b) + cos(delta_a) cos(delta_b) cos(alpha_a-alpha_b)
if ($fra1<>"" AND $fdec1<>"") {
  $theta1 = round(acos(sin($deltaSol*M_PI/180)*sin($fdecd1*M_PI/180) + cos($deltaSol*M_PI/180)*cos($fdecd1*M_PI/180)*cos(($alphaSol-$frad1)*M_PI/180))*180/M_PI*1000)/1000;
}
if ($fra2<>"" AND $fdec2<>"") {
  $theta2 = round(acos(sin($deltaSol*M_PI/180)*sin($fdecd2*M_PI/180) + cos($deltaSol*M_PI/180)*cos($fdecd2*M_PI/180)*cos(($alphaSol-$frad2)*M_PI/180))*180/M_PI*1000)/1000;
}

if ($fra1<>"" AND $fdec1<>"" AND $fra2<>"" AND $fdec2<>"") {
  $theta3 = round(acos(sin($fdecd1*M_PI/180)*sin($fdecd2*M_PI/180) + cos($fdecd1*M_PI/180)*cos($fdecd2*M_PI/180)*cos(($frad1-$frad2)*M_PI/180))*180/M_PI*1000)/1000;
  echo "Angular distance between Object #1 and Object #2 is: ".$theta3."°";
}

if (($fra1<>"" and $fdec1<>"") or ($fra2<>"" and $fdec2<>"")) {
  echo " RADecSolar elong.";
}
if ($fra1<>"" AND $fdec1<>"") {
  echo "Object #1:".$fra1."".$fdec1."      ".$theta1."°";
}
if ($fra2<>"" AND $fdec2<>"") {
  echo "Object #2:".$fra2."".$fdec2."      ".$theta2."°";
}


?>

> **Comments:**
> **username_0**: How would you compute the transit/solar noon from the RA and dec?  
> **username_1**: Local sidereal time is the RA of a star on your meridian and is offset from UT based on your longitude and the date. When your LST matches the Sun's RA then the Sun is on the meridian. (You don't need the Dec here.)  
> **username_0**: So the LST at longitude (and latitude?) needs to be computed and matched to the RA (of 103.0508°). That is the time of the solar noon? Sounds good.  
> **username_1**: The LST is just longitude-based (as is RA), so yes, when LST and RA of the Sun match then that is solar noon. The RA of the Sun will be slightly different at 8 am local time than at local noon (12 pm) and also at solar noon.  
> **username_0**: Seems like the topic is quite deep. Would you recommend any primers into astronomy? (Or would that be all? In which case: is is ok'ish to just use the RA from you without any time adjustment?)  
> **username_1**: There are so many aspects besides "looking at stuff in the sky" that I hesitate to suggest anything, but _Atlas of the Universe_ by Sir Patrick Moore is one of the first books that I read. And if that RA calculation works for you, then by all means use it.  
> **username_0**: In the end, the modified Java versions seems easier to use. Still, the glimpse into the why and how was helpful.  

---

