How do you get realistic textures when shading graphs?

2 views (last 30 days)
Elizabeth on 13 Sep 2022
Edited: Star Strider on 14 Sep 2022
x = @(r, t) r.*cos(t);
y = @(r, t) r.*sin(t);
z = @(r) 3.*r;
r = linspace(0, 2, 30);
t = linspace(0, 2*pi, 15);
[R, T] = meshgrid(r,t);
X = x(R,T);
Y = y(R,T);
Z = z(R);
surf(X, Y, Z)
hold on
x = @(r, t, p) r.*cos(t).*sin(p);
y = @(r, t, p) r.*sin(t).*sin(p);
z = @(r, p) r.*cos(p) + 6;
r = 2;
t = linspace(0, 2*pi, 100);
p = linspace(0, pi/2, 100);
[T, P] = meshgrid(t, p);
X = x(r, T, P);
Y = y(r, T, P);
Z = z(r, P);
surf(X, Y, Z)
hold off
axis off
mycolors = [0.9 0.66 0.4;
0.9 0.66 0.4;
0.9 0.66 0.4;
0.9 0.66 0.4;
0.9 0.66 0.4;
0.222 0.184 0.135;
0.635 0.078 0.184;
1 0 1];
colormap(mycolors)
axis equal
This is the code for an ice-cream shaped 3D graph. I would like to colour/shade the graph to look like a realistic ice cream but I cannot seem to find any information about how this is done if anyone can please help me.

Star Strider on 13 Sep 2022
Edited: Star Strider on 14 Sep 2022
I am not certain what result you want.
One option is to interpolate the ‘mycolors’ matrix —
x = @(r, t) r.*cos(t);
y = @(r, t) r.*sin(t);
z = @(r) 3.*r;
r = linspace(0, 2, 30);
t = linspace(0, 2*pi, 15);
[R, T] = meshgrid(r,t);
X = x(R,T);
Y = y(R,T);
Z = z(R);
surf(X, Y, Z)
hold on
x = @(r, t, p) r.*cos(t).*sin(p);
y = @(r, t, p) r.*sin(t).*sin(p);
z = @(r, p) r.*cos(p) + 6;
r = 2;
t = linspace(0, 2*pi, 100);
p = linspace(0, pi/2, 100);
[T, P] = meshgrid(t, p);
X = x(r, T, P);
Y = y(r, T, P);
Z = z(r, P);
surf(X, Y, Z)
hold off
axis off
icecream = [0.222 0.184 0.135;
0.635 0.078 0.184;
1 0 1]; % Original 'icecream' Part
icecreami = interp1((0:2), icecream, (0:0.1:2)); % Interpolate
mycolors = [0.9 0.66 0.4;
0.9 0.66 0.4;
0.9 0.66 0.4;
0.9 0.66 0.4;
0.9 0.66 0.4;
icecreami];
mycolors = [repmat(mycolors(1,:),50,1);
icecreami]; % New 'mycolors' Matrix
colormap(mycolors)
axis equal
See the documentation on the interp1 function for detailed information on it.
EDIT — (14 Sep 2022 at 1:06)
I just now remembered that the Lighting Overview may provide some help in working with the lighting propperties of your surface object. I am not experimenting with them here, because I am not certain what you want to do.
.

Image Analyst on 14 Sep 2022
Try
Sorry - I have no MATLAB code for bump mapping.

Categories

Find more on Surface and Mesh Plots in Help Center and File Exchange

R2022a

Community Treasure Hunt

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

Start Hunting!