Over-the-Horizon 3-D Views Using Camera Positioning Functions

You can create dramatic 3-D views using the Globe display. The camtargm and camposm functions (Mapping Toolbox functions corresponding to camtarget and campos) enable you to position focal point and a viewpoint, respectively, in geographic coordinates, so you do not need to deal with 3-D Cartesian figure coordinates.

In this exercise, you display coastlines from the landareas shapefile over topographic relief, and then view the globe from above Washington, D.C., looking toward Moscow, Russia.

Set up a Globe display and obtain topographic data for the map. Hide the map background.

axesm globe
load topo

Display topo without the vertical component (by omitting the fourth argument to meshm). The default view is from above the North Pole with the central meridian running parallel to the x-axis.


Add world coastlines from the global landareas shapefile and plot them in light gray.

coastlines = shaperead('landareas',...
    'UseGeoCoords', true, 'Attributes', {}); 
plotm([coastlines.Lat], [coastlines.Lon], 'Color', [.7 .7 .7])

Read the coordinate locations for Moscow and Washington from the worldcities shapefile.

moscow = shaperead('worldcities',...
    'Selector',{@(name) strcmpi(name,'Moscow'),'Name'});
washington = shaperead('worldcities',...
    'Selector',{@(name) strcmpi(name,'Washington D.C.'),...

Create a great circle track to connect Washington with Moscow and plot it in red.

[latc,lonc] = track2('gc',...
    moscow.Lat, moscow.Lon, washington.Lat, washington.Lon);

Point the camera at Moscow. Wherever the camera is subsequently moved, it always looks toward [moscow.Lat moscow.Lon].

camtargm(moscow.Lat, moscow.Lon, 0)

Station the camera above Washington. The third argument is an altitude in Earth radii.

camposm(washington.Lat, washington.Lon, 3)

Establish the camera up vector with the camera target's coordinates. The great circle joining Washington and Moscow now runs vertically.


Set the field of view for the camera to 20°.


Add a light and specify a relatively nonreflective surface material. This is the final view.

camlight; material(0.6*[ 1 1 1])

See Also

| | | |

Related Topics