how to make a smoothly connected plot on a sphere in MATLAB? -
this question has answer here:
- how plot data? 2 answers
there points on unit sphere , want join them smoothly along sphere smoothly how can in matlab,because when using 3dplot function in matlab joins point using straight lines.
for example there have point in first quadrant , second point in 8th quadrant join them using straight line. without following curved path.
these values of theta
:
theta = [ 80.0000 73.2995 65.7601 95.5007 100.4861 97.8834 94.0849 52.5174 74.4710 104.6674 52.7177 97.0538 75.7018 83.2817 97.5423 85.1797 84.2677 126.2296 81.1814 66.1376 91.6953 167.7085 46.5980 87.8220 113.4588 180.0000 80.7624 95.8623 115.0538 76.5773 61.9858 141.0402 109.9872 76.1273 84.4166 75.2734 110.4489 82.2434 96.8303 100.0815 73.2454 82.0755 64.6457 76.3510 87.7863 133.2706 86.1305 76.8670 86.3225 96.8016 49.2653 107.2900 145.9905 59.2158 107.7546 180.0000 93.9687 87.5474 103.1400 180.0000 136.8251 180.0000 106.2629 109.0069 ];
and values of phi
are:
phi = [ -90.0000 -78.5230 -51.6764 84.6854 58.1182 -75.9705 78.0541 -60.0560 88.8935 -84.6539 -44.1415 -86.7643 61.7764 -87.4767 -86.9440 -80.2459 -76.8752 88.9510 64.7297 -51.1245 -83.1606 -88.7280 -32.7110 81.0951 86.8393 -0.0000 52.6243 -88.7833 -75.4600 84.1374 79.8300 -86.7258 -65.8055 80.9829 -89.3172 57.1802 -80.6346 72.5277 -87.4452 74.2778 -86.1069 76.6124 -80.4604 89.2202 85.0649 89.2164 -79.0290 84.9961 -88.2301 -87.5064 50.4016 83.0830 82.4863 -50.8481 87.0335 -0.0000 88.4613 79.7583 -80.6474 -0.0000 80.0771 -0.0000 89.2428 -82.769 ];
can these poltted
if want matlab plot along unit sphere that, going need specify of points in between because matlab ever connect points straight line.
to this, can adapt roger stafford's great solution on matlab central draw shortest great circle path between 2 consecutive points.
using following function can that. determine shortest great circle path between 2 consecutive points , interpolate between them draw line on unit circle
function plotonsphere(x,y,z,varargin) %// vectors representing each point xyz = [x(:), y(:), z(:)].'; %' %// 1 vector of "first" points , 1 of "next" points v1 = xyz(:, 1:end-1); v2 = xyz(:, 2:end); %// cross product between vectors of 1 point , next cv1v2 = cross(v1, v2); %// compute unit vector in plane defined v1 , v2 v3 = normc(cross(cv1v2, v1)); %// figure out range of inner angle between v1 , v2 nc = sqrt(sum(cv1v2.^2, 1)); t = atan2(nc, dot(v1, v2, 1)); %// number of points sample between 2 points on sphere npoints = 100; %// compute interpolant v = zeros([npoints, fliplr(size(v1))]); k = 1:numel(t) t = linspace(0, t(k), 100); v(:,k,:) = (v1(:,k) * cos(t) + v3(:,k) * sin(t)).'; %' end %// break result out x,y,z parts xx = v(:,:,1); yy = v(:,:,2); zz = v(:,:,3); %// plot lines h = plot3(xx(:), yy(:), zz(:), varargin{:}); hold on %// plot original data points plot3(x,y,z, 'o', ... 'color', get(h, 'color'), ... 'parent', get(h, 'parent'), varargin{:}); end
if apply input data have provided.
theta = [ 80.0000 73.2995 65.7601 95.5007 100.4861 97.8834 94.0849 52.5174 74.4710 104.6674 52.7177 97.0538 75.7018 83.2817 97.5423 85.1797 84.2677 126.2296 81.1814 66.1376 91.6953 167.7085 46.5980 87.8220 113.4588 180.0000 80.7624 95.8623 115.0538 76.5773 61.9858 141.0402 109.9872 76.1273 84.4166 75.2734 110.4489 82.2434 96.8303 100.0815 73.2454 82.0755 64.6457 76.3510 87.7863 133.2706 86.1305 76.8670 86.3225 96.8016 49.2653 107.2900 145.9905 59.2158 107.7546 180.0000 93.9687 87.5474 103.1400 180.0000 136.8251 180.0000 106.2629 109.0069 ]; phi = [ -90.0000 -78.5230 -51.6764 84.6854 58.1182 -75.9705 78.0541 -60.0560 88.8935 -84.6539 -44.1415 -86.7643 61.7764 -87.4767 -86.9440 -80.2459 -76.8752 88.9510 64.7297 -51.1245 -83.1606 -88.7280 -32.7110 81.0951 86.8393 -0.0000 52.6243 -88.7833 -75.4600 84.1374 79.8300 -86.7258 -65.8055 80.9829 -89.3172 57.1802 -80.6346 72.5277 -87.4452 74.2778 -86.1069 76.6124 -80.4604 89.2202 85.0649 89.2164 -79.0290 84.9961 -88.2301 -87.5064 50.4016 83.0830 82.4863 -50.8481 87.0335 -0.0000 88.4613 79.7583 -80.6474 -0.0000 80.0771 -0.0000 89.2428 -82.769 ]; %// convert cartesian coordinates [x,y,z] = sph2cart(deg2rad(theta), deg2rad(phi), 1); figure; plotonsurface(x,y,z); %// plot unit sphere reference sphere() s = findall(gca, 'type', 'surf'); set(s, 'facecolor', 'k', 'facealpha', 0.01, 'edgealpha', 0.1)
Comments
Post a Comment