1manprojects / one_Sgp4

C# SGP4 orbit prediction Library
MIT License
62 stars 14 forks source link

Convert ECI to ECEF #27

Open JDragonB opened 1 year ago

JDragonB commented 1 year ago

Hello,

Is it possible to convert ECI coordinates to ECEF from the DLL?

I made a script in PowerShell, the import of the DLL works, the latitude is OK but the longitude does anything and I have curiously always an error of 20 km for the altitude:

$Block = $false
$Streams = Get-Item -LiteralPath "$PSScriptRoot\sgp4\One_Sgp4.dll" -Stream *
$Streams | ForEach-Object {if ($_.Stream -match "Zone.Identifier") {$Block = $true}}
if ($Block) {
    Unblock-File -LiteralPath "$PSScriptRoot\sgp4\One_Sgp4.dll"
    Write-Host -ForegroundColor Yellow -BackgroundColor Red "Un fichier a du être dévérouillé, veuillez redémarrer PowerShell pour la prise en compte"
    }
Add-Type -LiteralPath "$PSScriptRoot\sgp4\One_Sgp4.dll"

# Création d'un objet Satellite
$tleISS = New-Object One_Sgp4.Tle

#Analyse TLE
$tleISS = [One_Sgp4.ParserTLE]::parseTle("1 25544U 98067A   23021.58893016  .00026763  00000-0  47621-3 0  9995","2 25544  51.6443 334.6786 0004827 262.6903 262.3175 15.49939031379055","ISS (ZARYA)")

Write-host -BackgroundColor Black -ForegroundColor Cyan ("Nom du Satellite :    "+$tleISS.getName())
Write-host -BackgroundColor Black -ForegroundColor Cyan ("Numéro du Satellite : "+$tleISS.getSatNumber())

[double]$PI = [Math]::PI
$RayonTerreMin = 6356.752314
$RayonTerreMax = 6378.137
$Maintenant=(Get-Date).ToUniversalTime()
$MaintenantSGP4=[One_Sgp4.EpochTime]::new($Maintenant.Year,$Maintenant.DayOfYear+($Maintenant.Hour/24)+($Maintenant.Minute/1440)+($Maintenant.Second/86400))
$J2000 = [DateTime]'01/01/2000 11:58:55.816'
$Data = [One_Sgp4.SatFunctions]::getSatPositionAtTime($tleISS,$MaintenantSGP4,1)
$ECI_X= $Data.getX()
$ECI_Y= $Data.getY()
$ECI_Z= $Data.getZ()

$Longitude = 180*([Math]::Atan($ECI_Y/$ECI_X))/$PI
$Longitude = $Longitude + 280.46 + 360.9856123035484*(($Maintenant-$J2000).TotalDays) #Pour passer d'une coordonnée ECI à ECEF, il faut ajouter la rotation du temps sidéral par rapport à Greenwich (approximation)  
$Longitude = $Longitude % 360
if ($Longitude -gt 180) {$Longitude -= 360}

$LatitudeRad = [Math]::Atan($ECI_Z/([Math]::Sqrt(([Math]::Pow($ECI_X,2)+[Math]::Pow($ECI_Y,2)))))
$Latitude = ($LatitudeRad/$PI)*180

$RayonTerreP1 = ([Math]::Pow($RayonTerreMax,2))*([Math]::Pow($RayonTerreMax,2))
$RayonTerreP2 = ([Math]::Pow($RayonTerreMax,2))*([Math]::Pow([Math]::Sin($LatitudeRad),2))
$RayonTerreP3 = ([Math]::Pow($RayonTerreMin,2))*([Math]::Pow([Math]::Cos($LatitudeRad),2))
$RayonTerre = [Math]::Sqrt($RayonTerreP1/($RayonTerreP2+$RayonTerreP3))
$Altitude = [Math]::Sqrt([Math]::Pow($ECI_X,2)+[Math]::Pow($ECI_Y,2)+[Math]::Pow($ECI_Z,2)) - $RayonTerre

Write-host -BackgroundColor DarkGray -ForegroundColor Cyan "$Maintenant Z"
Write-host -BackgroundColor DarkGray -ForegroundColor yellow "ECI_X:$ECI_X km ECI_Y:$ECI_Y km ECI_Z:$ECI_Z km"
"Latitude:$Latitude N/S Longitude:$Longitude E/W Altitude:$Altitude km"

Thanks.

JDragonB commented 1 year ago

I found my happiness with the function [One_Sgp4.SatFunctions]::calcSatSubPoint :

$SP = [One_Sgp4.SatFunctions]::calcSatSubPoint($MaintenantSGP4,$Data,1)
$SP.getLatitude()
$SP.getLongitude()
$SP.getHeight()

Much easier than redoing the calculations, even if it's fun to do it myself.

Thanks for this DLL.

1manprojects commented 1 year ago

Very Good, Converting would be possible in the Library itself. Depending how it will devolope in the future i might implement more features.