Skip to content

GeoreferenceSystem

Quintin edited this page May 16, 2023 · 2 revisions

Georeference System

The Georeference System handles conversions between Unity coordinates and geospatial coordinates.

public class GeoreferenceSystem 
  : MonoBehaviour

Includes

Back to Top


Members

Access Type Name Description
const double EARTH_FLATTENING The WGS-84 inverse flattening value of the Earth.
const double EARTH_MAJOR_AXIS The WGS-84 equatorial radius of the Earth in meters.
const double EARTH_MINOR_AXIS The WGS-84 polar radius of the Earth in meters.
Public EEarthShape EarthShape The shape of the world in the scene.
Private dmat4 ECEFFrameToWorldFrame The matrix to transform a vector from ECEF CRS to Unity.
const double EPSILON Machine Epsilon - float approx 1e-7, double approx 2e-16
Private Vector3Double GeographicEllipsoid Vector containing ellipsoidal information pertaining to the WGS-84 Earth (X = EARTH_MAJOR_AXIS, Y = EARTH_MAJOR_AXIS, Z = EARTH_MINOR_AXIS).
Private Vector3Double OriginECEF The ECEF location of the Unity origin.
Public FLatLonAlt OriginLLA The Latitude in decimal degrees, Longitude in decimal degrees, and Altitude in meters of the Unity origin (0, 0, 0).
Private dmat4 UnityFrameToWorldFrame The matrix to transform a vector into the Unity coordinate frame.
Private dmat4 WorldFrameToECEFFrame The matrix to transform a vector from Unity to ECEF CRS.
Private dmat4 WorldFrameToUnityFrame The matrix to transform a vector from the Unity coordinate frame.

Back to Top


Functions

Access Return Name Description
Private void Awake() Awake is called when the script instance is being loaded.
Private Vector3Double ecef_to_flatearth(Vector3Double ecefLocation) Transforms the given ECEF XYZ location to a flat Earth coordinate.
Public Vector3 ECEFToUnity(Vector3Double ECEFLocation, Vector3 OriginRebasingOffset) Converts ECEF coordinates to Unity coordinates.
Private Vector3Double flatearth_to_ecef(Vector3Double FlatEarthCoords) Transforms the given flat Earth coordinates to an ECEF XYZ coordinate
Private FLatLonAlt flatearth_to_geodetic(Vector3Double FlatEarthCoords) Transforms the given flat Earth coordinates to geodetic Lat, Lon, Alt coordinates
Private Vector3Double geodetic_to_flatearth(FLatLonAlt latlonalt) Transforms the given geodetic Lat, Lon, Alt coordinate to a flat earth coordinate
Public FEastNorthUp GetENUVectorsAtECEFLocation(Vector3Double ECEFLocation) Get the East, North, Up vectors at the given ECEF location.
Public FEastNorthUp GetENUVectorsAtEngineLocation(Vector3 UnityLocation, Vector3 OriginRebasingOffset) Get the East, North, Up vectors at the given Unity location.
Public FNorthEastDown GetNEDVectorsAtECEFLocation(Vector3Double ECEFLocation) Get the North, East, Down vectors at the given ECEF location.
Public FNorthEastDown GetNEDVectorsAtEngineLocation(Vector3 UnityLocation, Vector3 OriginRebasingOffset) Get the North, East, Down vectors at the given Unity location.
Public Vector3Double GetOriginECEF() Gets the ECEF location of the Unity origin.
Public FLatLonAlt GetOriginLLA() Gets the Lat, Lon, Alt coordinates of the Unity origin.
Private string GetUTMLetterDesignator(double Lat) Gets the UTM letter designator for the given latitude.
Private dmat4 GetWorldFrameToECEFFrame(Vector3Double Ellisoid, Vector3Double ECEFLocation) Get the matrix to transform a vector from Unity to ECEF CRS.
Public FUTMCoordinates LatLonAltToProjected(FLatLonAlt LatLonAltToConvert) Converts the given Lat and Lon to UTM coordinates. Lat and Lon should be in decimal degrees.
Public Vector3 LatLonAltToUnity(FLatLonAlt LatLonAlt, Vector3 OriginRebasingOffset) Converts the given Lat, Lon, Alt coordinates to Unity coordinates.
Private void SetupVars() Initializes the needed variables that are used for geospatial conversions.
Public Vector3Double UnityToECEF(Vector3 UnityLocation, Vector3 OriginRebasingOffset) Converts Unity coordinates into ECEF coordinates.
Public FLatLonAlt UnityToLatLonAlt(Vector3 UnityLocation, Vector3 OriginRebasingOffset) Converts Unity coordinates into geodetic Lat, Lon, Alt coordinates.

Back to Top


Details

EARTH_FLATTENING

const double EARTH_FLATTENING = 298.257223563

The WGS-84 inverse flattening value of the Earth.

Back to Top


EARTH_MAJOR_AXIS

const double EARTH_MAJOR_AXIS = 6378137

The WGS-84 equatorial radius of the Earth in meters.

Back to Top


EARTH_MINOR_AXIS

const double EARTH_MINOR_AXIS = 6356752.314245

The WGS-84 polar radius of the Earth in meters.

Back to Top


EarthShape

public EEarthShape EarthShape

The shape of the world in the scene.

Back to Top


ECEFFrameToWorldFrame

private dmat4 ECEFFrameToWorldFrame

The matrix to transform a vector from ECEF CRS to Unity.

Back to Top


EPSILON

const double EPSILON = 2.220446049250313e-16

Machine Epsilon - float approx 1e-7, double approx 2e-16

Back to Top


GeographicEllipsoid

private Vector3Double GeographicEllipsoid = new Vector3Double
{
    X = EARTH_MAJOR_AXIS,
    Y = EARTH_MAJOR_AXIS,
    Z = EARTH_MINOR_AXIS
}

Vector containing ellipsoidal information pertaining to the WGS-84 Earth.

Back to Top


OriginECEF

private Vector3Double OriginECEF

The ECEF location of the Unity origin.

Back to Top


OriginLLA

public FLatLonAlt OriginLLA

The Latitude in decimal degrees, Longitude in decimal degrees, and Altitude in meters of the Unity origin (0, 0, 0).

Back to Top


UnityFrameToWorldFrame

private dmat4 UnityFrameToWorldFrame

The matrix to transform a vector into the Unity coordinate frame.

Back to Top


WorldFrameToECEFFrame

private dmat4 WorldFrameToECEFFrame

The matrix to transform a vector from Unity to ECEF CRS.

Back to Top


WorldFrameToUnityFrame

private dmat4 WorldFrameToUnityFrame

The matrix to transform a vector from the Unity coordinate frame.

Back to Top


Awake

private void Awake()

Awake is called when the script instance is being loaded.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html

Back to Top


ecef_to_flatearth

private Vector3Double ecef_to_flatearth
(
    Vector3Double ecefLocation
)

Transforms the given ECEF XYZ location to a flat Earth coordinate.

Parameter Description
ecefLocation The ECEF location to transform.
Returns
The X (East), Y (North), and Z (Up) location in a flat Earth coordinate system.

Back to Top


ECEFToUnity

public Vector3 ECEFToUnity
(
    Vector3Double ECEFLocation,
    Vector3 OriginRebasingOffset = default
)

Converts ECEF coordinates to Unity coordinates.

Parameter Description
ECEFLocation The ECEF location to transform.
OriginRebasingOffset The offset that has been applied to the origin if any origin shifting has been performed.
Returns
The Unity coordinates.

Back to Top


flatearth_to_ecef

private Vector3Double flatearth_to_ecef
(
    Vector3Double FlatEarthCoords
)

Transforms the given flat Earth coordinates to an ECEF XYZ coordinate

Parameter Description
FlatEarthCoords The flat Earth X (East), Y (North), and Z (Up) coordinate to transform.
Returns
The ECEF XYZ location.

Back to Top


flatearth_to_geodetic

private FLatLonAlt flatearth_to_geodetic
(
    Vector3Double FlatEarthCoords
)

Transforms the given flat Earth coordinates to geodetic Lat, Lon, Alt coordinates

Parameter Description
FlatEarthCoords The flat Earth X (East), Y (North), and Z (Up) coordinate to transform.
Returns
The Lat in decimal degrees, Lon in decimal degrees, and Alt in meters.

Back to Top


geodetic_to_flatearth

private Vector3Double geodetic_to_flatearth
(
    FLatLonAlt latlonalt
)

Transforms the given geodetic Lat, Lon, Alt coordinate to a flat earth coordinate

Parameter Description
latlonalt The Lat in decimal degrees, Lon in decimal degrees, and Alt in meters to transform.
Returns
The X (East), Y (North), and Z (Up) location in a flat Earth coordinate system.

Back to Top


GetENUVectorsAtECEFLocation

public FEastNorthUp GetENUVectorsAtECEFLocation
(
    Vector3Double ECEFLocation
)

Get the East, North, Up vectors at the given ECEF location.

Parameter Description
ECEFLocation The ECEF location to get the East, North, Up vectors of.
Returns
The East, North, Up vectors in terms of Unity's coordinate system

Back to Top


GetENUVectorsAtEngineLocation

public FEastNorthUp GetENUVectorsAtEngineLocation
(
    Vector3 UnityLocation,
    Vector3 OriginRebasingOffset = default
)

Get the East, North, Up vectors at the given Unity location.

Parameter Description
UnityLocation The Unity location to get the East, North, Up vectors of.
OriginRebasingOffset The offset that has been applied to the origin if any origin shifting has been performed.
Returns
The East, North, Up vectors in terms of Unity's coordinate system.

Back to Top


GetNEDVectorsAtECEFLocation

public FNorthEastDown GetNEDVectorsAtECEFLocation
(
    Vector3Double ECEFLocation
)

Get the North, East, Down vectors at the given ECEF location.

Parameter Description
ECEFLocation The ECEF location to get the North, East, Down vectors of.
Returns
The North, East, Down vectors in terms of Unity's coordinate system

Back to Top


GetNEDVectorsAtEngineLocation

public FNorthEastDown GetNEDVectorsAtEngineLocation
(
    Vector3 UnityLocation,
    Vector3 OriginRebasingOffset = default
)

Get the North, East, Down vectors at the given Unity location.

Parameter Description
UnityLocation The Unity location to get the North, East, Down vectors of.
OriginRebasingOffset The offset that has been applied to the origin if any origin shifting has been performed.
Returns
The North, East, Down vectors in terms of Unity's coordinate system.

Back to Top


GetOriginECEF

public Vector3Double GetOriginECEF()

Gets the ECEF location of the Unity origin.

Back to Top


GetOriginLLA

public FLatLonAlt GetOriginLLA()

Gets the Lat, Lon, Alt coordinates of the Unity origin.

Back to Top


GetUTMLetterDesignator

private string GetUTMLetterDesignator
(
    double Lat
)

Gets the UTM letter designator for the given latitude.

Parameter Description
Lat The latitude to get the UTM letter designator of. Should be given in decimal degrees.
Returns
A string containing the UTM letter designator.

Back to Top


GetWorldFrameToECEFFrame

private dmat4 GetWorldFrameToECEFFrame
(
    Vector3Double Ellisoid,
    Vector3Double ECEFLocation
)

Get the matrix to transform a vector from Unity to ECEF CRS.

Parameter Description
Ellisoid The ellipsoid of the world.
ECEFLocation The ECEF to get the world frame of.
Returns
The transformation matrix needed to convert Unity locations to ECEF CRS.

Back to Top


LatLonAltToProjected

public FUTMCoordinates LatLonAltToProjected
(
    FLatLonAlt LatLonAltToConvert
)

Converts the given Lat and Lon to UTM coordinates. Lat and Lon should be in decimal degrees.

Parameter Description
LatLonAltToConvert The Lat and Lon to convert
Returns
The UTM Coordinates.

Back to Top


LatLonAltToUnity

public Vector3 LatLonAltToUnity
(
    FLatLonAlt LatLonAlt,
    Vector3 OriginRebasingOffset = default
)

Converts the given Lat, Lon, Alt coordinates to Unity coordinates.

Parameter Description
LatLonAlt The Lat, Lon, Alt coordinates to transform.
OriginRebasingOffset The offset that has been applied to the origin if any origin shifting has been performed.
Returns
The Unity coordinates.

Back to Top


SetupVars

private void SetupVars()

Initializes the needed variables that are used for geospatial conversions.

Back to Top


UnityToECEF

public Vector3Double UnityToECEF
(
    Vector3 UnityLocation,
    Vector3 OriginRebasingOffset = default
)

Converts Unity coordinates into ECEF coordinates.

Parameter Description
UnityLocation The Unity coordinates to transform.
OriginRebasingOffset The offset that has been applied to the origin if any origin shifting has been performed.
Returns
The ECEF XYZ coordinates.

Back to Top


UnityToLatLonAlt

public FLatLonAlt UnityToLatLonAlt
(
    Vector3 UnityLocation,
    Vector3 OriginRebasingOffset = default
)

Converts Unity coordinates into geodetic Lat, Lon, Alt coordinates.

Parameter Description
UnityLocation The Unity coordinates to transform.
OriginRebasingOffset The offset that has been applied to the origin if any origin shifting has been performed.
Returns
The Lat, Lon, Alt coordinates.

Back to Top