# Calculating the sun’s position in ECI

I’m trying to calculate visible ISS passes and I need to calculate if the ISS is behind the earth by “drawing” a line between the ISS and the sun and seeing if it crosses earth. I have the ECI position of the ISS, but I don’t have the position of the sun. How do I calculate the suns ECI position given a date and time?

Edit: I need to use c# for this so I can’t use python libraries

If you know how to use python, you can do something like :

import astropy as ap
ap.coordinates.get_sun(time)


It will return a position in geocentric coordinates for the given time.

• Unfortunately I am using c# not python. – Nick Brown Dec 19 '18 at 17:24
• Then, i don't know how to help you ... sorry – Yoann A. Dec 19 '18 at 20:51
public static Vector3 GetSunDirection(DateTime time)
{
time = time.ToUniversalTime();
double JD = 367*time.Year-Math.Floor(7.0*(time.Year+Math.Floor((time.Month+9.0)/12.0))/4.0)+Math.Floor(275.0*time.Month/9.0)+time.Day+1721013.5+time.Hour/24.0+time.Minute/1440.0+time.Second/86400.0;
double pi = 3.14159265359;
double UT1 = (JD-2451545)/36525;
double longMSUN = 280.4606184+36000.77005361*UT1;
double mSUN = 357.5277233+35999.05034*UT1;
double ecliptic = longMSUN+1.914666471*Math.Sin(mSUN*pi/180)+0.918994643*Math.Sin(2*mSUN*pi/180);
double eccen = 23.439291-0.0130042*UT1;

double x = Math.Cos(ecliptic*pi/180);
double y = Math.Cos(eccen*pi/180)*Math.Sin(ecliptic*pi/180);
double z = Math.Sin(eccen*pi/180)*Math.Sin(ecliptic*pi/180);

return new Vector3(x, y, z);
}

public static Vector3 GetSun(DateTime time)
{
double sunDistance = 0.989 * 1.496E+8;
var sunPosition = GetSunDirection(time.ToUniversalTime());

sunPosition = sunPosition * sunDistance;

return sunPosition;
}