plot - Showing 3D data on a patch surface with Matlab -
i want show, matlab, temperature distribution on object surface.
i've got 3d data in form of (x, y, z, v) vectors. show object in matlab, colour representing local total "value".
i can export object stl file. can shown using stl plotting (see stldemo):
fv = stlread('file.stl'); patch(fv, 'edgecolor', 'none', 'facelighting', 'gouraud', 'ambientstrength', 0.15, 'facecolor', [0.8 0.8 1.0]); camlight('headlight'); material('dull'); to colour according (x,y,z,v), need attach each (x, y, z) point vertex in patch (the nearest 1 work). if there many (x,y,z) points single stl vertex nearest, add corresponding v values vertex.
the number of vertices thousands. number of (x, y, z) points large. doing loop through (x, y, z) points , internal loop on vertices find nearest 1 (which involves calculating distances between points) out of question. there smart way quickly?
note: cannot control location of data points, defined external program. stl points controlled external program. have marry 2 different point sets.
here code illustrating want achieve, 4 vertices , 3 data points:
% create patch figure; p = patch; colorbar p.vertices = [... 0, 0, 0; ... 1, 0, 0; ... 1, 1, 0; 0, 1, 0]; p.faces = [ ... 1, 2, 3; ... 1, 3, 4]; % data points x = [0.1, 0.1, 0.25]; y = [0.01, 0.02, 0.75]; z = [0.01, 0.2, -0.01]; v = [1, 1, 1]; p.facevertexcdata = zeros(size(p.vertices, 1), 1); % point 1 (0.1, 0.01, 0.01) closest vertex 1 (0, 0, 0). value % goes vertex 1. p.facevertexcdata(1) = p.facevertexcdata(1) + v(1); % point 2 (0.1, 0.02, 0.2) closest vertex 1 (0, 0, 0). % value goes vertex 1 p.facevertexcdata(1) = p.facevertexcdata(1) + v(2); % point 3 (0.25, 0.75, -0.01) closest vertex 4 (0, 1, 0). power % goes vertex 4. p.facevertexcdata(4) = p.facevertexcdata(4) + v(3); % other vertices left 0. p.facecolor = 'interp';
attaching volume scalar value (of temperature in case) of point neighbouring point tricky exercise, requires complex for loops , defining special case rules (in case wanted attach value of 2 different points same patch vertex, if 2 values attach different? average? discard ?).
a safer approach re-interpolate temperature field on object surface. function griddata can you.
first had define scalar field. since not have temperature data, use flow function matlab. generated scalar field same ways in article: flow data.
gave me scalar field v (flow value let's it's temperature) @ every coordinates x, y, z.

then created , introduced 3d patch object. chose sphere 3d patch work same way. code sphere patch borrowed surf2patch
you have offset , inflate sphere in figure below

now interesting bit. in following code, v value of scalar field (temperature you) @ coordinates x, y, z.
%% // extract patch vertices coordinates in separate variables xp = fv.vertices(:,1) ; yp = fv.vertices(:,2) ; zp = fv.vertices(:,3) ; %% // interpolate temperature field on patch coordinates tpv = griddata(x,y,z,v,xp,yp,zp) ; %% // set patch color data new interpolated temperature set(hp,'facevertexcdata',tpv) ; and object surface @ right interpolated temperature:
you can delete slice plane if want observe patch alone

Comments
Post a Comment