# Calculation Problems with Lat/Lon

## Recommended Posts

I am Working on an Addition to KER which I called Decelleration Readouts, which essentialy does the same as suicide Burn Readouts, but is more Versatile and gives more information. https://github.com/harryyoung/KerbalEngineer

Video Demonstration (earlier iteration)  https://youtu.be/6Rb1LDvKdok

I am Stuck at accurately determining the landing point based on vessel lat/lon and the horizontal Breaking distance. Ironically I get the correct Longditude, however my Latitude is off, making all information relying on that unusable. I use the Following to determine Lat/Long

```//do impact site calculations, special thanks to Muddr for Pointing me to http://www.movable-type.co.uk/scripts/latlong.html
surfaceRotation = GetSurfaceRotation();
var incl = surfaceRotation.eulerAngles.y;
var currentlat = FlightGlobals.ActiveVessel.latitude;
var currentlon = FlightGlobals.ActiveVessel.longitude;
var angdst = 360 * HorizontalDistance / (2 * Math.PI * FlightGlobals.currentMainBody.Radius);
var bodyrot = 360 * DecelerationTime / FlightGlobals.ActiveVessel.mainBody.rotationPeriod;

impactLatitude = currentlat + Math.Asin(Math.Sin(currentlat)*Math.Cos(angdst)+Math.Cos(currentlat)*Math.Sin(angdst)*Math.Cos(incl));
impactLongitude = 360 + bodyrot + currentlon + Math.Atan2(Math.Sin(incl)*Math.Sin(angdst)*Math.Cos(currentlat), Math.Cos(angdst)-Math.Sin(currentlat)*Math.Sin(impactLatitude));```

Do any of you know what I am doing wrong?

##### Share on other sites
45 minutes ago, harryyoung said:

Do any of you know what I am doing wrong?

Without understanding in detail what you are doing, I note two things:

* How come inclination goes into it and not LAN? The result must somehow depend not only on how far your orbit is from equatorial, but also in which direction it is tilted. This would affect latitude more than longitude, so it might be the error you are looking for.

* Lat/Lon is quite an awkward coordinate system to do calculations (because it breaks the symmetry of the sphere in a quite arbitrary way). It is often more convenient to use normalized vectors for calculations and convert the result to Lat/Lon. For example I find it much more convenient to use the orbit normal vector for calculations instead of Inc and LAN.

##### Share on other sites

it's actally not inclinatiopn, but heading over surface, I did not rename the variable.

as for Normal vectors I'd love to go there. I even need that for some Information I guess, but when I tried i produced NaN's like Crazy, so I decided to try o go for Lat/Lon calc first to get an Idea for my target point... It did not fruit and now I'm stuck

I got it Cracked. Funny thing with Trigonometry is it does not care if your distances are Linear or in degrees

Edited by harryyoung

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.