Last active
November 13, 2022 07:54
-
-
Save sukesh-ak/fcdf69570f44616fd0f66bcf4052a026 to your computer and use it in GitHub Desktop.
Spherical to Cartesian coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Converts Spherical to Cartesian coordinates | |
int earthRadius = 6367; //radius in km | |
private Cartesian convertSphericalToCartesian(double latitude, double longitude) | |
{ | |
var lat = DegreesToRadians(latitude); | |
var lon = DegreesToRadians(longitude); | |
var x = earthRadius * Math.Cos(lat) * Math.Cos(lon); | |
var y = earthRadius * Math.Cos(lat) * Math.Sin(lon); | |
var z = earthRadius * Math.Sin(lat); | |
return new Cartesian(x, y, z); | |
} | |
private class Cartesian | |
{ | |
public double X { get; set; } | |
public double Y { get; set; } | |
public double Z { get; set; } | |
public Cartesian(double x, double y, double z) | |
{ | |
X = x; | |
Y = y; | |
Z = z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment