2

I want to plot vertical planes in geo-projected figures from the Matlap Mapping toolbox. Imagine four vertical faces of a cube like in this example resembling this question. The problem is that Matlab doesn't plot all faces correctly as you can see in the example below:

Example Cube with a missing face and overlapping base

Minimal code example using geoshow:

xf = [ 0, 1, 1, 0;
       1, 1, 0, 0;
       1, 1, 0, 0;
       0, 1, 1, 0  ]
   
yf = [ 0, 0, 1, 1;
       0, 1, 1, 0;
       0, 1, 1, 0;
       0, 0, 1, 1 ]
    
zf = [ 0,   0,   0,   0;
       0,   0,   0,   0;
      .01, .01, .01, .01;
      .01, .01, .01, .01 ]
   
figure
axesm('miller');
geoshow(xf,yf,zf,'DisplayType','surface','FaceColor','red','FaceAlpha',0.4);
xlabel('lat')
ylabel('lon')
zlabel('alt')
view(-140,-60);

The documentation for geoshow says:

geoshow(lat,lon,Z) projects and displays a geolocated data grid.

Z: M-by-N array. May contain NaN values.

My guess is that the Z variable must be defined differently, but how? Or is there another solution? I really feel like ramming my head against the wall...

Community
  • 1
  • 1
JaBe
  • 664
  • 1
  • 8
  • 27

1 Answers1

1

I think there are two things going wrong in your example:

  1. MATLAB is drawing faces you don't want because you have four rows in xf, yf and zf ... edges are drawn between horizontally and vertically adjacent points.
  2. The last column of xf (similarly yf and zf) should be the same as the first, to "close" the box (i.e. draw the one vertical wall you're missing)

My solution:

After some playing, it looks like one solution is to define your xf, yf, and zf as follows:

  • zf = 2-by-n matrix, top row all zeros, bottom row all the desired height of the walls (for you, 0.1; for my example below, 1)
  • xf = 2-by-n matrix, top and bottom rows identical, giving the latitude coordinates of the square defining your region
  • Similarly, yf = 2-by-n matrix, top and bottom rows identical, giving the longitude coordinates of the square defining your region.

Important notes:

  • the first and last columns of xf, yf, and zf should be identical to "close" the room
  • xf corresponds to latitude which is actually y coordinates here, and vice-versa for yf

One Wall:

Just trying to get a feel for geoshow I started with one wall:

geoshow([1 1; 1 1], [0 1; 0 1], [0 0; 1 1], ...
        'displaytype','surface','facecolor','red','facealpha',0.5);
view(3); xlabel('x'); ylabel('y'); zlabel('z');

Notice the first input (all 1's) corresponds to the y-values, since they are latitudes: One wall

Two Walls:

I added another column to each xf, yf, and zf:

geoshow([1 1 0; 1 1 0], [0 1 1; 0 1 1], [0 0 0; 1 1 1],... 
        'displaytype','surface','facecolor','red','facealpha',0.5);
view(3); xlabel('x'); ylabel('y'); zlabel('z');

Two Walls (note: I adjusted the axis here to match the first picture for consistency)

Three Walls:

I added another column to each xf, yf, and zf:

geoshow([1 1 0 0; 1 1 0 0],[0 1 1 0; 0 1 1 0],[0 0 0 0; 1 1 1 1],...
         'displaytype','surface','facecolor','red','facealpha',0.5);
view(3); xlabel('x'); ylabel('y'); zlabel('z');

Three Walls (note: there is no top on the "box")

Four Walls:

I added another column (a copy of the first column) to each xf, yf, and zf:

geoshow([1 1 0 0 1; 1 1 0 0 1],[0 1 1 0 0; 0 1 1 0 0],[0 0 0 0 0; 1 1 1 1 1],...
         'displaytype','surface','facecolor','red','facealpha',0.5);
view(3); xlabel('x'); ylabel('y'); zlabel('z');

Four Walls

Ta-da! To convince you there's no top on the box: No Top!

Geoff
  • 1,202
  • 10
  • 18