Clear Filters
Clear Filters

How to transform cartesian or polar data to latitude longitude ?

42 views (last 30 days)
# sorry if my english is bad
Hello, like the title of this question, i need to compute a Cartesian Points or Polar Points to Geographic coordinates ( Latitude and Longitude ) if the ThetaZeroLocation is on top and the x,y,z axis is like this.
where the 0,0,0 coordinate is the center of a radar. the radar location : latitude = -6.1275 , longitude = 106.6537, with height = 3 m above the ground.
i have the real data location of a target on the radar in all 3 coordinates, cartesian, polar, and latitude longitude. I want to transform the cartesian or polar data to geographic coodinates.
Im making a function that have several code to compute this problem,
for case 1 and 2, i get the reference from this site [https://vvvv.org/blog/polar-spherical-and-geographic-coordinates#:~:text=In%20order%20to%20match%20the,a%20longitude%20of%200%C2%B0.]
for case 3 [https://stackoverflow.com/questions/5674149/3d-coordinates-on-a-sphere-to-latitude-and-longitude]
and for case 4 [https://www.researchgate.net/post/How-to-determine-the-latitude-and-longitude-of-a-target]
function Data = Cart2LatLong(latRad,longRad,initData,n)
%X Y Z in Nautycal Mile
for i = 1:size(initData,1)
X = initData{i,1}(:,2);
Y = initData{i,1}(:,3);
Z = initData{i,1}(:,6)/6076; % ft to KM to NM
Zm = initData{i,1}(:,6)*0.3048; %ft to meter
switch n
case 1
r = sqrt(X.^2 + Y.^2 + Z.^2);
Data{i,1}(:,1) = asin(Z./r)+latRad;
Data{i,1}(:,2) = atan2(Y, X)+longRad;
Data{i,1}(:,3) = X;
Data{i,1}(:,4) = Y;
Data{i,1}(:,5) = Z;
Data{i,1}(:,6) = Zm;
case 2
r = sqrt(X.^2 + Y.^2 + Z.^2);
Data{i,1}(:,1) = asin(Z./r)+latRad;
Data{i,1}(:,2) = atan2(X,-Y)+longRad;
Data{i,1}(:,3) = X;
Data{i,1}(:,4) = Y;
Data{i,1}(:,5) = Z;
Data{i,1}(:,6) = Zm;
case 3
r = sqrt(X.^2 + Y.^2 + Z.^2);
Data{i,1}(:,1) = atan2(Z,r)+latRad;
Data{i,1}(:,2) = atan2(X,-Y)+longRad;
Data{i,1}(:,3) = X;
Data{i,1}(:,4) = Y;
Data{i,1}(:,5) = Z;
Data{i,1}(:,6) = Zm;
case 4
R_Tgt = initData{i,1}(:,4); % Data in NM ( Nautycal Mile )
T_Tgt = initData{i,1}(:,5); % Data in NM
Z_Tgt = Z*1.15078; % NM to mile
R1 = 3959 + 0.0057556603249355915708;
T1 = longRad;
Phi1 = 90-latRad;
R2 = R_Tgt*1.15078; % NM to mile
T2 = 90-T_Tgt; % Because the zero location is on top, so the theta 90-theta
Phi2 = 90-Z_Tgt;
%% Extract NaN data
[R1,T1,Phi1] = extractNan3D(R1,T1,Phi1);
[R2,T2,Phi2] = extractNan3D(R2,T2,Phi2);
%% Transform polar data to cartesian
[x1,y1,z1]= pol2car(Phi1,T1,R1);
[x2,y2,z2]= pol2car(Phi2,T2,R2);
x = x1+x2; y = y1+y2; z = z1+z2; %final cartesian
%final polar
R = sqrt(x.^2+y.^2+z.^2);
Theta = atan2(y,x);
Phi = atan2(sqrt(x.^2+y.^2),z.^2);
Lat = 90 - Phi;
Long = Theta;
Data{i,1}(:,1)= Lat+latRad;
Data{i,1}(:,2)= Long+longRad;
end
end
end
% coba function di matlab
function [x,y,z] = pol2car (phi,theta,rho)
x = rho.*sin(phi).*cos(theta);
y = rho.*sin(phi).*sin(theta);
z = rho.*cos(phi);
end
function [x,y,z] = extractNan3D(x1,y,z)
indnan = find(isnan(x1)); %find index that the data is NaN
x = x1(setdiff(1:length(x1),indnan));
y = y(setdiff(1:length(x1),indnan));
z = z(setdiff(1:length(x1),indnan));
end
so for example, the x,y,z,rho data in NM (Nautycal mile) and theta is
X = 0.578125000000000; Y = 11.0781250000000; Z = 7.55842659644503; rho = 11.0976562500000; theta = 2.99926757812500
the real latitude longitude is
latitude = -5.942989 ; longitude = 106.663383
but what i got from each program is
%n = 1
latitude = -5.529427552; longitude = 108.1723574;
%n = 2
latitude = -5.529427552; longitude = 109.7431538;
%n = 3
latitude = -5.614692417; longitude = 109.7431538;
%n = 4
latitude = 83.86984703; longitude = 106.4941534; %the longitude data result is the closest one to the real longitude
so am i have making a totally wrong code or just wrong in some line ? need help thank you.
  1 Comment
Zaidan Adenin Said
Zaidan Adenin Said on 25 May 2021
this is the data that i use for this problem
% X (NM) Y (NM) Rho (NM) The (deg) Z (ft)
0.578125000000000 11.0781250000000 11.0976562500000 2.99926757812500 45925
1.01562500000000 11.0546875000000 11.1015625000000 5.27893066406250 45925
1.46093750000000 11.0078125000000 11.1015625000000 7.55859375000000 45925
1.89843750000000 10.9375000000000 11.1054687500000 9.84375000000000 45925
2.32812500000000 10.8593750000000 11.1093750000000 12.1234130859375 45925
% Lat_Real Long_Real
-5.942989 106.663383
-5.94338 106.67071
-5.94416 106.678168
-5.945331 106.685496
-5.946633 106.692692

Sign in to comment.

Accepted Answer

Zaidan Adenin Said
Zaidan Adenin Said on 31 May 2021
So i think i found the answer. From the toolbox Automated driving ther is one function that work fine to me.
so im just convert X,Y, and Z data with NM to meter. And because my data is already ENU form, so im not changing any direction. and the origin just a vector contain latitude, longitude, and the height of my radar.

More Answers (0)

Categories

Find more on Polar Plots in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!