I C# Accurate Earth, Moon Sun visual model to predict eclipses

AI Thread Summary
A user is developing a C# visual model to predict lunar and Earth eclipses using accurate ephemeris data. They seek guidance on modeling the system in the Earth-Centered Earth-Fixed (ECEF) reference frame, specifically regarding the reference epoch, time scale (considering Terrestrial Time), and ephemeris models. The user is exploring the use of SOFA and CSPICE for celestial object positioning but is unsure how to implement these in C#. They are looking for tutorials or shortcuts to streamline their understanding and development process. The discussion highlights the challenges of transitioning from C to C# and the availability of resources for code conversion.
TheGalaxyOfGold
Messages
7
Reaction score
1
Hello all!

I am trying to make a VISUAL model (in C#) to predict lunar and Earth eclipse periods for a satellite that I have accurate ephemeris for.

I want to calculate everything in ECEF reference frame.

How would a go about modeling this system to the accuracy I'm interested in?

I assume I need the following:

1) A reference epoch that coincides with a particular position of moon and position/orientation of earth.
- how would I arrive at this?

2) A time scale, I assume I can use Terrestrial Time, please correct me if I'm wrong.

3) an ephemeris model.
- I would like to be able to update celestial object positions according to a time-slider and/or stop/start button which proceeds at a specified pace. Would calculating my own ephemeris be necessary, or can I use the JPL Horizons data?

4) An Earth rotation model. This one is mainly so that I can report coordinates accurately in ECEF, which is the reference frame that I'm interested in.

I'm thoroughly bewildered after looking through SOFA documentation. After about an hour of reading I guess I got that I can just use a Terrestrial Time scale, but I'm not real sure how I would use SOFA (certainly I have more to read) to implement my objectives. I've also heard of CSPICE, used by NASA, but haven't looked into it yet because I saw that the toolkit was offered in C, and I don't know if I can use that for a C# program, as I'm not sure how that works.

I'm basically just getting started, but any guidance or tutorials or hints/shortcuts that anyone can provide to me will be very much appreciated, and save me a lot of lurking around in the dark until I realize what it is that I need.

Thank you so much in advance!
 
Last edited:
Astronomy news on Phys.org
If you have code in one language and need it in another, its possible to convert it line by line. This requires understanding both languages enough to do that. However, sometimes it can be quite daunting especially if they are based on different paradigms.

In the C to C# case, I don't think the port would be too difficult as they are both "C" style languages. Of course, you're probably going from procedural to object oriented but that is an easy mapping.

To get an idea of what it might take look at the rosettacode.org site. They have many examples of tasks solved in a multitude of languages and while in many cases they are not direct ports of one another you can still see how things are done in C and then done in C#.

Here's a list of C# examples, of which many have C versions too:

http://rosettacode.org/wiki/Category:C_sharp

and here's Ackermans function as an example:

http://rosettacode.org/wiki/Ackermann_function

The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.The Ackermann function is usually defined as follows:{\displaystyle A(m,n)={\begin{cases}n+1&{\mbox{if }}m=0\\A(m-1,1)&{\mbox{if }}m>0{\mbox{ and }}n=0\\A(m-1,A(m,n-1))&{\mbox{if }}m>0{\mbox{ and }}n>0.\end{cases}}}Its arguments are never negative and it always terminates. Write a function which returns the value of {\displaystyle A(m,n)}. Arbitrary precision is preferred (since the function grows so quickly), but not required.

and the C# code:

C#:
using System;
class Program
{
    public static long Ackermann(long m, long n)
    {
        if(m > 0)
        {
            if (n > 0)
                return Ackermann(m - 1, Ackermann(m, n - 1));
            else if (n == 0)
                return Ackermann(m - 1, 1);
        }
        else if(m == 0)
        {
            if(n >= 0)
                return n + 1;
        }
 
        throw [URL='http://www.google.com/search?q=new+msdn.microsoft.com']new[/URL] System.ArgumentOutOfRangeException();
    }
 
    static void Main()
    {
        for (long m = 0; m <= 3; ++m)
        {
            for (long n = 0; n <= 4; ++n)
            {
                Console.WriteLine("Ackermann({0}, {1}) = {2}", m, n, Ackermann(m, n));
            }
        }
    }
}

and the C version:

C:
#include <stdio.h>
 
int ackermann(int m, int n)
{
        if (!m) return n + 1;
        if (!n) return ackermann(m - 1, 1);
        return ackermann(m - 1, ackermann(m, n - 1));
}
 
int main()
{
        int m, n;
        for (m = 0; m <= 4; m++)
                for (n = 0; n < 6 - m; n++)
                        [URL='http://www.opengroup.org/onlinepubs/009695399/functions/printf.html']printf[/URL]("A(%d, %d) = %d\n", m, n, ackermann(m, n));
 
        return 0;
}
 
Last edited:
  • Like
Likes BvU
Wow, I wasn't expecting someone to answer, but I'm sure it will be helpful. Thank you!
 
Is a homemade radio telescope realistic? There seems to be a confluence of multiple technologies that makes the situation better than when I was a wee lad: software-defined radio (SDR), the easy availability of satellite dishes, surveillance drives, and fast CPUs. Let's take a step back - it is trivial to see the sun in radio. An old analog TV, a set of "rabbit ears" antenna, and you're good to go. Point the antenna at the sun (i.e. the ears are perpendicular to it) and there is...
3I/ATLAS, also known as C/2025 N1 (ATLAS) and formerly designated as A11pl3Z, is an iinterstellar comet. It was discovered by the Asteroid Terrestrial-impact Last Alert System (ATLAS) station at Río Hurtado, Chile on 1 July 2025. Note: it was mentioned (as A11pl3Z) by DaveE in a new member's introductory thread. https://www.physicsforums.com/threads/brian-cox-lead-me-here.1081670/post-7274146 https://earthsky.org/space/new-interstellar-object-candidate-heading-toward-the-sun-a11pl3z/ One...
Back
Top