Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to plot a polygon over 3D earth surface like Google Earth

196 views
Skip to first unread message

Yash

unread,
Jan 26, 2013, 11:58:08 AM1/26/13
to
In Google Earth kml file, it's possible to specify [lat, long] coordinates of vertices of a polygon and that polygon shows up on Google (spherical) Earth in 3D.

I tried to do something like this. I used sphere followed by surf to plot 3D Earth. I converted the vertices of lat, long of the polygon by sph2cart into x, y, z. I tried using patch(x,y,z,'k'), but the patch cuts into and goes behind the convex shaped earth section and so cannot be seen. See the following thread.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/326078

Does anyone know a way out. Basically I want to plot a sphere and put a polygonal spherical patch on that sphere whose boundaries are specified in [theta, phi] (say, r is a constant). If I used patch or fill3, the patch created is a planar patch instead of a spherical cut, and so it does not serve my purpose.

Is there a way to do this in Matlab what Google Earth kml does.

Yash

unread,
Jan 28, 2013, 3:23:10 PM1/28/13
to
Following the suggestion mentioned on the following thread

http://www.mathworks.com/matlabcentral/newsreader/view_thread/11300

of creating the points of a sphere and replacing those that don't fall within the desired polygon by NaNs, I was able to create a spherical patch function.

Not sure if there is any better way, but here is the piece of code FWIW.

function sphericalPatch(theta,phi,clr,alpha,r)

% alpha and phi define the [az, el] vertices of the polygonal shape
% clr is the color of the patch, alpha is the transparency and r is the sphere radius

[xb, yb, zb] = sphereMy(350,1,theta,phi,r);
surf(xb,yb,zb,'facecolor',clr,'facealpha',alpha,'edgecolor','none')

function [x, y, z] = sphereMy(varargin)

% create [x, y, z] coordinates of a sphere
% replace those x, y, z by NaNs that don't fall within the prescribed polygon

n = 20; if nargin > 0, n = varargin{1}; end
pH = 0; if nargin > 1, pH = varargin{2}; end
thetaT = 0; if nargin > 2, thetaT = varargin{3}; end
phiT= 0; if nargin > 3, phiT = varargin{4}; end
r = 1; if nargin > 4, r = varargin{5}; end

az = linspace(-pi,pi,n);
elev = linspace(-pi/2,pi/2,n);
[thetaA,phiA]=meshgrid(az,elev);
[x, y, z] = sph2cart(thetaA,phiA,r);
if pH,
inOut = inpolygon(thetaA,phiA,thetaT,phiT);
x(~inOut)=NaN;
y(~inOut)=NaN;
z(~inOut)=NaN;
end


"Yash" wrote in message <ke11v0$64o$1...@newscl01ah.mathworks.com>...
0 new messages