How to use isocolor with you own color condition ?

2 views (last 30 days)
Teerapong Poltue
Teerapong Poltue on 7 Nov 2020
Answered: Aghamarsh Varanasi on 10 Nov 2020
I'm using a code
interval = [-3:0.1:3];
a= interval ;
b= interval;
c= interval;
[A,B,C] = meshgrid(a,b,c);
data = cos(A) + cos(B) + cos(C);
cdata = smooth3(rand(size(data)),'box',7);
p = patch(isosurface(A,B,C,data,0));
p.FaceColor = 'interp';
p.EdgeColor = 'none';
daspect([1 1 1])
axis tight
lighting gouraud
but now the color grandient is given by random, I would like to give a gradient by k which is the function of coordinate x y z how can I do that
syms x y z
f = cos(x) + cos(y) + cos(z);
fx = diff(f,x);
fy = diff(f,y);
fz = diff(f,z);
fxx = diff(fx,x);
fxy = diff(fx,y);
fxz = diff(fx,z);
fyx = diff(fy,x);
fyy = diff(fy,y);
fyz = diff(fy,z);
fzx = diff(fz,x);
fzy = diff(fz,y);
fzz = diff(fz,z);
mat = [fxx fxy fxz fx; fyx fyy fyz fy; fzx fzy fzz fz; fx fy fz 0];
no = det(mat);
de = (fx^2 + fy^2 + fz^2)^2;
k = de/no;

Answers (1)

Aghamarsh Varanasi
Aghamarsh Varanasi on 10 Nov 2020
You can use the 6th argument of ‘isosurface to change the color gradient of the isosurface.
Here is an example
[x,y,z,v] = flow;
[faces,verts,colors] = isosurface(x,y,z,v,-3,x);
patch('Vertices', verts, 'Faces', faces, ...
'FaceVertexCData', colors, ...
'FaceColor','interp', ...
'edgecolor', 'interp')
Note that as x increases, the color goes from the dark blue to the red.
For reference you can check this example


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!