I have a data set coming form a GPS sensor which is giving me the value in geodetic coordinates (lat, long, alt) and I want to convert it into UTM coordinates. I am trying two approaches and apparently, the answer is varying and with a large difference. Now, I can't validate which answer is correct. Could anyone please help me.
My first approach is using the formula and running it for all the values of latitude and longitude that I have. The latitude and longitude are in degrees and the altitude is in meters. So the code is transforming the formula and is giving me the values. The code is attached.
I found out the command [X,Y] = ll2utm (lat,long) and I am using this. This has lat and long in degrees only and is returning me x and y in meters.
trucklat = degtorad(lat);
trucklon = degtorad(long);
trailat = degtorad(lat1);
trailon = degtorad(long1);
a = 6378137;
e = 8.1819190842622e-2;
Ntrail = a ./ sqrt(1 - e^2 .* sin(trailat).^2);
Ntruck = a ./ sqrt(1 - e^2 .* sin(trucklat).^2);
truck.x = (Ntruck+alt) .* cos(trucklat) .* cos(trucklon);
truck.y = (Ntruck+alt) .* cos(trucklat) .* sin(trucklon);
truck.z = ((1-e^2) .* Ntruck + alt) .* sin(trucklat);
trailer.x = (Ntrail+alt1) .* cos(trailat) .* cos(trailon);
trailer.y = (Ntrail+alt1) .* cos(trailat) .* sin(trailon);
trailer.z = ((1-e^2) .* Ntrail + alt1) .* sin(trailat);