How to plot coastlines on 3D earth

22 views (last 30 days)
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.

Accepted Answer

Ryan Klots
Ryan Klots on 12 Feb 2021
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 Comments
Cielo Martos
Cielo Martos on 13 Feb 2021
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 on 14 Feb 2021
Nevermind I see the problem now!
plot3(-X, -Y, Z, "Color", "red", "LineWidth", 5);

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!