# Calculate Inverse Coordinate

Theory

The inverse of a spherical coordinate can be calculated by taking the inverse of the latitude (θ) and offsetting the longitude (Φ) by 180˚. The following formulas can be used to calculate these values.

The sgn function, known as the sign function and signum function, is a complex function that extracts the sign of a real number. This function has the following characteristics:

The inverse of a Cartesian coordinate can be calculated by taking the x, y, and z components of the coordinate and multiply them by -1.

Application

The function to calculate the inverse coordinate will take in a VELatLong object and will return a VELatLong object. There is not a sgn function in the JavaScript Math class but we can do this using simple logic.

`function inverseSpherical(latlong){     var lat = -1*latlong.Latitude;     var lon = 180-Math.abs(latlong.Longitude);     if(latlong.Longitude>0)         lon *= -1;     return new VELatLong(lat,lon);}`

Listing 1 Inverse Spherical Coordinate

The following algorithm calculates the inverse coordinate of a Cartesian coordinate. This algorithm takes in a Cartesian coordinate and returns a Cartesian coordinate.

`function inverseCartesian(p1){     return new Cartesian(-1*p1.X,-1*p1.Y,-1*p1.Z);}`

Listing 2 Inverse Cartesian Coordinate

The following post has additional information on the Cartesian object: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!280.entry