How to plot coastlines on 3D earth

23 ビュー (過去 30 日間)
Cielo Martos
Cielo Martos 2021 年 2 月 11 日
コメント済み: Cielo Martos 2021 年 2 月 14 日
I'm trying to plot coastlines on a 3D Earth I made
E=wgs84Ellipsoid
[x,y,z] = ellipsoid(0,0,0,E.SemimajorAxis,E.SemimajorAxis,E.SemiminorAxis);
s = surface(x,y,z);
[N,R] = egm96geoid;
s.FaceColor = 'texturemap';
s.CData = N;
So far this is what I have and i want to overlay coastlines from the mapping toolbox but, I don't know how to do that.

採用された回答

Ryan Klots
Ryan Klots 2021 年 2 月 12 日
Currently, you are plotting (x, y, z) data as you would on a Cartesian axes. If you want to combine this with (lat, lon) data, you need to somehow convert between the two.
For example, you could use the geodetic2ecef function from Mapping Toolbox to convert from (lat, lon) coordinates to (x, y, z) coordinates:
% Load coastline data
load coastlines
% Convert from (lat, lon) coordinates to (x, y, z) coordinates
[X, Y, Z] = geodetic2ecef(E, coastlat, coastlon, 0); % E is your reference ellipsoid
% Plot (x, y, z) coastline data on top of existing sphere
hold on
plot3(X, Y, Z, "Color", "red", "LineWidth", 5);
hold off
Alternatively, you could consider sticking with (lat, lon) data exclusively and using something like geoglobe:
% Load coastline data
load coastlines
% Initialize geoglobe
f = uifigure();
g = geoglobe(f);
% Plot coastlines on geoglobe
geoplot3(g, coastlat, coastlon, 0, "Color", "red", "LineWidth", 5);
In either case, it's critical to pay attention to the coordinate system that you are working in.
  2 件のコメント
Cielo Martos
Cielo Martos 2021 年 2 月 13 日
Thank you so much! the first set of code did the trick! However, the onl problem is that the coast lines don't line up with the actual coasts. As you can see the Australia coastline is over South America.
Cielo Martos
Cielo Martos 2021 年 2 月 14 日
Nevermind I see the problem now!
plot3(-X, -Y, Z, "Color", "red", "LineWidth", 5);

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by