Skip to content

MASINavigation

MOARdV edited this page Nov 19, 2017 · 26 revisions

MASINavigation.cs

Contents

CAUTION: These methods are subject to change as this code matures.

MASINavigation encapsulates navigation functionality, including emulating radio navigation. It provides methods to determine the distance from the vessel to a particular lat/lon location on the planet, and the distance between two arbitrary points on a planet.

All methods use the current vessel's parent body as the body for calculations.

Equations adapted from http://www.movable-type.co.uk/scripts/latlong.html.


General Navigation Category

The General Navigation section contains general-purpose navigational formulae that can be used for navigation near a planet's surface.

nav.Bearing(double latitude1, double longitude1, double latitude2, double longitude2)

  • latitude1: Latitude of position 1 in degrees. Negative values indicate south, positive is north.
  • longitude1: Longitude of position 1 in degrees. Negative values indicate west, positive is east.
  • latitude2: Latitude of position 2 in degrees. Negative values indicate south, positive is north.
  • longitude2: Longitude of position 2 in degrees. Negative values indicate west, positive is east.

Returns: Bearing (heading) in degrees.

Returns the great-circle route bearing from (lat1, lon1) to (lat2, lon2).

nav.BearingFromVessel(double latitude, double longitude)

  • latitude: Latitude of the destination point in degrees. Negative values indicate south, positive is north.
  • longitude: Longitude of destination point in degrees. Negative values indicate west, positive is east.

Returns: Hearing in degrees from the vessel to the destination.

Returns the great-circle bearing from the vessel to the specified lat/lon coordinates.

nav.DestinationLatitude(double latitude, double longitude, double range, double bearing)

  • latitude: Latitude of the point of origin. Negative values indicate south, positive is north.
  • longitude: Longitude of the point of origin. Negative values indicate west, positive is east.
  • range: Distance to travel along the bearing, in meters.
  • bearing: Bearing in degrees to travel.

Returns: Latitude in degrees.

Returns the latitude found at the given range along the given bearing.

TODO: Replace fc.DestinationLatitude and fc.DestinationLongitude with fc.DestinationCoordinates which returns latitude and longitude at the same time so computations do not need to be made twice.

nav.DestinationLatitudeFromVessel(double range, double bearing)

  • range: Distance to travel along the bearing, in meters.
  • bearing: Bearing in degrees to travel.

Returns: Latitude in degrees.

Returns the latitude found at the given range along the given bearing from the current vessel.

nav.DestinationLongitude(double latitude, double longitude, double range, double bearing)

  • latitude: Latitude of the point of origin. Negative values indicate south, positive is north.
  • longitude: Longitude of the point of origin. Negative values indicate west, positive is east.
  • range: Distance to travel along the bearing, in meters.
  • bearing: Bearing in degrees to travel.

Returns: Longitude in degrees.

Returns the longitude found at the given range along the given bearing from the point of origin.

nav.DestinationLongitudeFromVessel(double range, double bearing)

  • range: Distance to travel along the bearing, in meters.
  • bearing: Bearing in degrees to travel.

Returns: Longitude in degrees.

Returns the longitude found at the given range along the given bearing from the current vessel.

nav.GroundDistance(double latitude1, double longitude1, double latitude2, double longitude2)

  • latitude1: Latitude of position 1 in degrees. Negative values indicate south, positive is north.
  • longitude1: Longitude of position 1 in degrees. Negative values indicate west, positive is east.
  • latitude2: Latitude of position 2 in degrees. Negative values indicate south, positive is north.
  • longitude2: Longitude of position 2 in degrees. Negative values indicate west, positive is east.

Returns: Distance in meters between the two points, following the surface of the planet.

Return the ground distance between two coordinates on a planet.

Assumes the planet is the one the vessel is currently orbiting / flying over. Uses the sea-level altitude.

nav.GroundDistanceFromVessel(double latitude, double longitude)

  • latitude: Latitude of the destination point in degrees. Negative values indicate south, positive is north.
  • longitude: Longitude of destination point in degrees. Negative values indicate west, positive is east.

Returns: Distance in meters between the two points, following the surface of the planet.

Return the ground distance between the vessel and a location on the surface of the planet.

Uses the sea-level altitude.

nav.LineOfSight(double altitude)

  • altitude: Altitude above sea level, in meters.

Returns: Distance to the horizon, in meters.

Returns the distance to the horizon based on a given altitude ASL.

The horizon is assumed to be at sea level. Due to the small sizes of most stock KSP worlds, and the relatively large mountains, this number will not be reliable for estimating whether a given land position is within line-of-sight.


Radio Navigation Category

The Radio Navigation section provides methods for emulating navigational radio on board aircraft (or ships, or whatever).

Most methods are centered around a selected radio (the radioId parameter, and they assume all computations in relation to the current active vessel. Because these methods emulate navigational radios, they account for limitations caused by the curvature of the planet as well as limited radio broadcasting distances.

Because of this, methods may return values indicating "no signal" even if the radio is tuned to a correct value.

The radioId parameter may be any integer (non-integer numbers are converted to integers). MAS does not place any restrictions on how many radios are used on a vessel, not does it place restrictions on what radio ids may be used. If the IVA creator wishes to use ids 2, 17, and 21, then MAS allows it.

Frequency is assumed to be in MHz, and MAS assumes radios have about a 10kHz minimum frequency separation (real-world VOR uses 50kHz), so setting a radio to 105.544 will select any navaids on a frequency between 105.494 and 105.594.

nav.GetNavAidDME(double radioId)

  • radioId: The id of the radio, any integer value.

Returns: As described in the summary.

Queries the radio beacon selected by radioId to determine if it includes DME equipment. Returns one of three values:

  • -1: No navaid beacons are in range on the current frequency.
  • 0: A navaid beacon is in range, but it does not support DME.
  • 1: A navaid beacon is in range, and it supports DME.

nav.GetNavAidType(double radioId)

  • radioId: The id of the radio, any integer value.

Returns: As described in the summary.

Returns the type of radio beacon the radio currently is detecting. Returns one of three values:

  • 0: No navaid beacons are in range on the current frequency.
  • 1: Beacon is NDB.
  • 2: Beacon is VOR.
  • 3: Beacon is ILS.

nav.GetRadioFrequency(double radioId)

  • radioId: The id of the radio, any integer value.

Returns: 0 if the radio does not have a frequency set, otherwise, the frequency.

Returns the radio frequency setting for the specified radio.

nav.SetRadioFrequency(double radioId, double frequency)

  • radioId: The id of the radio, any integer value.
  • frequency: The frequency of the radio, assumed in MHz.

Returns: 1 if the radio was switched off, or if any radios have a frequency within 10kHz of the requested frequency (regardless of range).

Sets the specified navigational radio to the frequency.

If frequency is less than or equal to 0.0, the radio is switched off.


This documentation was automatically generated from source code at 15:23 UTC on 19/Nov/2017.

Clone this wiki locally