public double Geocent_ep2; // 2nd eccentricity squared //************************************************************************** // METHODS //************************************************************************** // The function Set_Geocentric_Parameters receives the ellipsoid parameters // as inputs and sets the corresponding state variables. // // a : Semi-major axis, in meters. (input) // b : Semi-minor axis, in meters. (input) public GEOCENT pj_Set_Geocentric_Parameters(double a, double b) { GEOCENT Error_Code = GEOCENT.NO_ERROR; if (a <= 0.0) { Error_Code |= GEOCENT.A_ERROR; } if (b <= 0.0) { Error_Code |= GEOCENT.B_ERROR; } if (a < b) { Error_Code |= GEOCENT.A_LESS_B_ERROR; } if (Error_Code == 0) { Geocent_a = a; Geocent_b = b; Geocent_a2 = a * a; Geocent_b2 = b * b; Geocent_e2 = (Geocent_a2 - Geocent_b2) / Geocent_a2; Geocent_ep2 = (Geocent_a2 - Geocent_b2) / Geocent_b2; } return(Error_Code); }
// The function Convert_Geodetic_To_Geocentric converts geodetic coordinates // (latitude, longitude, and height) to geocentric coordinates (X, Y, Z), // according to the current ellipsoid parameters. // // Latitude : Geodetic latitude in radians (input) // Longitude : Geodetic longitude in radians (input) // Height : Geodetic height, in meters (input) // X : Calculated Geocentric X coordinate, in meters. (output) // Y : Calculated Geocentric Y coordinate, in meters. (output) // Z : Calculated Geocentric Z coordinate, in meters. (output) public GEOCENT pj_Convert_Geodetic_To_Geocentric(double Latitude, double Longitude, double Height, out double X, out double Y, out double Z) { GEOCENT Error_Code = GEOCENT.NO_ERROR; double Rn; // Earth radius at location double Sin_Lat; // sin(Latitude) double Sin2_Lat; // Square of sin(Latitude) double Cos_Lat; // cos(Latitude) // Don't blow up if Latitude is just a little out of the value // range as it may just be a rounding issue. Also removed longitude // test, it should be wrapped by cos() and sin(). NFW for PROJ.4, Sep/2001. if (Latitude < -Proj.HALFPI && Latitude > -1.001 * Proj.HALFPI) { Latitude = -Proj.HALFPI; } else if (Latitude > Proj.HALFPI && Latitude < 1.001 * Proj.HALFPI) { Latitude = Proj.HALFPI; } else if ((Latitude < -Proj.HALFPI) || (Latitude > Proj.HALFPI)) { Error_Code |= GEOCENT.LAT_ERROR; // Latitude out of range } if (Error_Code == 0) // no errors { if (Longitude > Proj.PI) { Longitude -= 2 * Proj.PI; } Sin_Lat = Math.Sin(Latitude); Cos_Lat = Math.Cos(Latitude); Sin2_Lat = Sin_Lat * Sin_Lat; Rn = Geocent_a / (Math.Sqrt(1.0 - Geocent_e2 * Sin2_Lat)); X = (Rn + Height) * Cos_Lat * Math.Cos(Longitude); Y = (Rn + Height) * Cos_Lat * Math.Sin(Longitude); Z = ((Rn * (1 - Geocent_e2)) + Height) * Sin_Lat; } else { X = Y = Z = double.NaN; } return(Error_Code); }