How can you plot lines of latitude and longitude on a globe without using the mapping toolbox ?

57 ビュー (過去 30 日間)
I have a function that displays the countries of the world on a global plot and I need to know how to plot lines of lat and lon in even increments of 10 degrees onto this global plot without using the geoshow command found in the mapping toolbox.
  3 件のコメント
Rik
Rik 2017 年 7 月 25 日
You could even use plot3 to generate the wire mesh.
As to examples: spherical coordinates work similar to polar coordinates (x=r*sin(theta),y=r*cos(theta)), so you can expand that to 3D without too much trouble.
per isakson
per isakson 2017 年 7 月 26 日
Maybe it's worth looking in the File Exchange. Try lon lat plot.

サインインしてコメントする。

採用された回答

Chad Greene
Chad Greene 2017 年 8 月 2 日
編集済み: MathWorks Support Team 2022 年 6 月 8 日
Update - as for R2018b, the geoplot function in MATLAB can be used as a way to plot latitude and longitude data on a 2-D global map.
*******
You can do this easily with the standard matlab function sph2cart. Treat the lines of latitude and longitude separately like this:
R = 6371; % earth radius in km
latspacing = 10;
lonspacing = 20;
% lines of longitude:
[lon1,lat1] = meshgrid(-180:lonspacing:180,linspace(-90,90,300));
[x1,y1,z1] = sph2cart(lon1*pi/180,lat1*pi/180,R);
plot3(x1,y1,z1,'-','color',0.5*[1 1 1])
hold on
% lines of latitude:
[lat2,lon2] = meshgrid(-90:latspacing:90,linspace(-180,180,300));
[x2,y2,z2] = sph2cart(lon2*pi/180,lat2*pi/180,R);
plot3(x2,y2,z2,'-','color',0.5*[1 1 1])
axis equal tight off
And since you can see all the way through the globe, perhaps you want to put an opaque sphere inside the globe. Do that like this. I'm making the sphere 0.99 times the size of the Earth just to make sure it doesn't overlap the lines of lat and lon:
[X,Y,Z] = sphere(100);
surf(X*R*.99,Y*R*.99,Z*R*.99,'facecolor','w','edgecolor','none')
For a little context, I'll also convert national borders to cartesian coordinates in the same way. You'll need the data from my borders function for this part:
C = load('borderdata.mat');
for k = 1:246
[xtmp,ytmp,ztmp] = sph2cart(deg2rad(C.lon{k}),deg2rad(C.lat{k}),R);
plot3(xtmp,ytmp,ztmp,'k')
end
  6 件のコメント
Marisabel Gonzalez
Marisabel Gonzalez 2019 年 2 月 15 日
How could you plot a lat/lot point and a declination and inclination point?
Sam Polk
Sam Polk 2021 年 6 月 10 日
編集済み: Sam Polk 2021 年 6 月 10 日
@Chad Greene This is great! I modified your code using the wgs84Ellipsoid and geodetic2ecef functions to do these same plots on a spheroid (rather than a sphere). This code is given below:
% Plot lines of longitude:
[lon_lon,lat_lon] = meshgrid(-180:lonspacing:180,linspace(-90,90,300)); % lat-long coordinates of our longitude mesh
[xlon,ylon,zlon] = geodetic2ecef(wgs84Ellipsoid('meter'), lon_lon, lat_lon, 0); % Converts to [x,y,z] on surface of earth
plot3(xlon, ylon, zlon ,'-','color',0.5*[1 1 1])
hold on
% Plot lines of latitude:
[lat_lat,lon_lat] = meshgrid(-90:latspacing:90,linspace(-180,180,300)); % lat-long coordinates of our lattitude mesh
[xlat,ylat,zlat] = geodetic2ecef(wgs84Ellipsoid('meter'), lon_lat, lat_lat, 0); % Converts to [x,y,z] on surface of earth
plot3(xlat,ylat,zlat,'-','color',0.5*[1 1 1])
I had some trouble adding the plot of maps, however. Let me know if you have any suggestions!

サインインしてコメントする。

その他の回答 (1 件)

Chad Greene
Chad Greene 2019 年 3 月 8 日
I turned my answer into a collection of functions called globeplot, globesurf, globegraticule, globeborders, etc. which you can find in the Climate Data Toolbox for Matlab.
  2 件のコメント
Margareta
Margareta 2019 年 3 月 8 日
Dear Chad,
thank you so much for sharing the "half Earth" code example earlier (last September), and for also going to the trouble of providing this really nice and nifty set of functions as part of the CD toolbox!
Cheers from Sweden!
Maggie
Chad Greene
Chad Greene 2019 年 3 月 8 日
Thanks so much for saying that, Maggie!

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by