Lat Long to metric coordinates

Topics: General, Windows Forms
Jun 6, 2013 at 3:24 PM
Hello to everyone, i wrote this class. I'd like to have some advice...
public class convertitore
        {

            public string zonautm;
            public int lngzonautm;
            public char latzonautm;
            public double latutm;
            public double lngutm;

            public void latlongtoutm(double lat, double lng)
            
            {
                lngzonautm = Convert.ToInt16(31 + Math.Floor(lng / 6));
                int valore = Convert.ToInt16 (Math.Floor(lat/8));
                if (valore >= -10)
                    latzonautm = 'C';
                if (valore >= -9)
                    latzonautm = 'D';
                if (valore >= -8)
                    latzonautm = 'E';
                if (valore >= -7)
                    latzonautm = 'F';
                if (valore >= -6)
                    latzonautm = 'G';
                if (valore >= -5)
                    latzonautm = 'H';
                if (valore >= -4)
                    latzonautm = 'J';
                if (valore >= -3)
                    latzonautm = 'K';
                if (valore >= -2)
                    latzonautm = 'L';
                if (valore >= -1)
                    latzonautm = 'M';
                if (valore >= 0)
                    latzonautm = 'N';
                if (valore >= 1)
                    latzonautm = 'P';
                if (valore >= 2)
                    latzonautm = 'Q';
                if (valore >= 3)
                    latzonautm = 'R';
                if (valore >= 4)
                    latzonautm = 'S';
                if (valore >= 5)
                    latzonautm = 'T';
                if (valore >= 6)
                    latzonautm = 'U';
                if (valore >= 7)
                    latzonautm = 'V';
                if (valore >= 8)
                    latzonautm = 'W';
                if (valore >= 9)
                    latzonautm = 'X';
                 zonautm = lngzonautm.ToString()+latzonautm;
               
                //Costanti del Datum WGS84
                double Latrad = lat * Math.PI / 180;
                double Lngrad = lng * Math.PI / 180;
                double e1sq = 0.006739497;
                double a = 6378137.0;//Raggio equatoriale
                double b = 6356752.3;//raggio polare
                double f = (a - b) / a;//schiacciamento
                double fi = 1/f; //inverso deoo schiacciamento;
                double rm = Math.Pow((a * b), 0.5);
                double k0 = 0.9996;
                double e =Math.Sqrt(1 - Math.Pow((b / a), 2));
                double e2 = e * e / (1 - e * e);
                double n = (a - b) + (a + b);
                double rho = (a * (1 - e * e)) / Math.Pow((1 - Math.Pow((e * Math.Sin(Latrad)), 2)), 1.5);
                double nu = a / Math.Pow(1 - Math.Pow((e * Math.Sin(Latrad)), 2), 0.5);
                double A0 = 6367449.146;
                double B0 = 16038.42955;
                double C0 = 16.83261333;
                double D0 = 0.021984404;
                double E0 = 0.000312705;
                double S = A0 * Latrad - B0 * Math.Sin(2 * Latrad) + C0 * Math.Sin(4 * Latrad) - D0 * Math.Sin(6 * Latrad) + E0 * Math.Sin(8 * Latrad);
                double longZoneCM = 6 * lngzonautm - 183;
                double DeltaLongRAD = (lng - longZoneCM) * Math.PI / 180;
                double ki = S * 0.9996;
                double kii = nu * Math.Sin(Latrad) * Math.Cos(Latrad)* k0 / 2;
                double kiii = (nu * Math.Sin(Latrad) * Math.Pow(Math.Cos(Latrad), 3)/24)*(5-Math.Pow(Math.Tan(Latrad),2)+9*e1sq*Math.Pow(Math.Cos(Latrad),2)+4*Math.Pow(e1sq,2)*Math.Pow(Math.Cos(Latrad),4)*k0);
                double kiv = nu * Math.Cos(Latrad) * k0;
                double kv = Math.Pow(Math.Cos(Latrad),3)*(nu/6)*(1-Math.Pow(Math.Tan(Latrad),2)+e1sq*Math.Pow(Math.Cos(Latrad),2))*k0;
                latutm = ki+kii*DeltaLongRAD*DeltaLongRAD+kiii*Math.Pow(DeltaLongRAD,4);
                lngutm = 500000 + (kiv * DeltaLongRAD + kv * Math.Pow(DeltaLongRAD, 3));
                
                
            }

          
        }