How to plot latitude, longitude, altitude, and heading/direction in 3D space?
35 views (last 30 days)
Show older comments
MathWorks Support Team
on 24 Apr 2019
Edited: MathWorks Support Team
on 24 Apr 2019
How can I plot latitude, longitude, altitude, and heading/direction in 3D space?
For example, I have two points, each defined by latitude, longitude, and altitude. At each point, I would like to specify a "heading", i.e. a compass direction specified in degrees clockwise from "true North".
I would then like to plot/visualize these as arrows/lines that 1) start from the initial latitude/longitude/altitude coordinates, and 2) are oriented along the respective heading directions.
Accepted Answer
MathWorks Support Team
on 25 Apr 2019
Edited: MathWorks Support Team
on 24 Apr 2019
I can suggest two possible approaches to visualize the arrows/lines, as determined from the initial latitude/longitude/altitude coordinates and the headings. Details are included below, and further below is an example to help illustrate each approach.
1) The first approach leverages the Mapping Toolbox's built-in support to create rhumb lines, given an initial set of latitude/longitude coordinate and a heading.
2) The second approach is to manually compute the x/y/z components of the arrow/direction from the heading angle and then using the "quiver3" function to plot the arrow emanating from the initial latitude/longitude/altitude coordinate.
Here is an example to illustrate each of the above approaches.
Setup:
Create example data, e.g. initial coordinates set to Boston and Bangalore.
clear all
close all
clc
%Initial latitude/longitude coordinates for Boston and Bangalore
lat0 = [42,13];
lon0 = [-71,77];
%Altitude coordinates
alt0 = [0,0];
%Headings, in units of degrees clockwise relative to "true North"
az = [135,-90];
Approach #1:
Create rhumb lines - via the "track1" function - from the initial coordinates and headings.
%Note that the "track1" function accepts initial lat/lon coordinates and a
%heading as inputs and can be used to generate a rhumb line track along
%that maintains the heading
arclen = 150; %In units of degrees of arc
[lat1,lon1] = track1('rh',lat0(1),lon0(1),az(1),arclen);
[lat2,lon2] = track1('rh',lat0(2),lon0(2),az(2),arclen);
%Create a map axes with a specified projection, e.g. "globe" or "mercator"
%(execute "doc axesm" for details)
figure
axesm globe; framem on; gridm on; view(3)
% axesm mercator; framem on; gridm on; mlabel on; plabel on; view(2)
%First, plot world coastlines, simply for visualization reference purposes
load coastlines
plotm(coastlat,coastlon)
%Plot the rhumb line for the first track
%(starting at Boston, with a heading of 135 degrees clockwise of North,
%i.e. Southeast)
scatterm(lat0(1),lon0(1),'r')
plot3m(lat1,lon1,alt0(1)*ones(size(lat1)),'r-')
%Plot the rhumb line for the second track
%(starting at Bangalore, with a heading of -90 degrees clockwise of North,
%i.e. West)
scatterm(lat0(2),lon0(2),'g')
plot3m(lat2,lon2,alt0(2)*ones(size(lat1)),'g-')
Approach #2:
Plot in 3D axes (i.e. not a map axes) via the "quiver3" function.
%Manually calculate the components of the vectors from the headings.
%Note that the headings have been defined as angles in degrees clockwise
%relative to "true North"
len = 50; %Length of arrow to plot
u = len.*cosd(90-az);
v = len.*sind(90-az);
%Specify the changes in altitudes
w = [0,0];
%Visualize the resultant arrows in a 3D plot
figure
scale = 0; %Use scale = 0 to plot the vectors without any automatic scaling
quiver3(lon0,lat0,alt0,u,v,w,scale)
view(2)
xlabel('Longitude')
ylabel('Latitude')
zlabel('Altitude')
0 Comments
More Answers (0)
See Also
Categories
Find more on Mapping Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!