How to plot coordinate data to appear solid with lighting effect?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have quite delicate problem.
In the for loop I am plotting these circles using
plot3(x,y,z)
so after number of iteration it make this body of a certain shape.
I was searching everywhere but is it possible to plot these points to look more like solid/surface with lighting like as in the example below
The problem is that quite often these surfaces will cross itself like in the example here
so I also need to setup opacity of the resulting surface to see through.
I cannot provide any data because they are huge, but I would be gratefull for similar problem because I tried everything.
0 comentarios
Respuestas (2)
Kevin Holly
el 1 de Oct. de 2021
Editada: Kevin Holly
el 1 de Oct. de 2021
There may be a better way doing it. Here is my attempt:
x1 = 0;
x2 = 0;
y1 = -.8; % value based on angle of 25 degrees
y2 = .8; % value based on angle of 25 degrees
eccentricity = .78;
numPoints = 300; % Less for a coarser ellipse, more for a finer resolution.
% Make equations:
a = (1/2) * sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2);
b = a * sqrt(1-eccentricity^2);
t = linspace(0, 2 * pi, numPoints); % Absolute angle parameter
X = a * cos(t);
Y = b * sin(t);
% Compute angles relative to (x1, y1).
angles = atan2(y2 - y1, x2 - x1);
x = (x1 + x2) / 2 + X * cos(angles) - Y * sin(angles);
y = (y1 + y2) / 2 + X * sin(angles) + Y * cos(angles);
figure
subplot (2,2,1)
plot3(x,y,zeros(size(y)))
hold on
plot3(x,y,0.5*ones(size(y)))
hold on
plot3(x,y,ones(size(y)))
axis equal
X = [x x x];
Y = [y y y];
Z = [zeros(size(y)) 0.5*ones(size(y)) ones(size(y))];
T=delaunayTriangulation(X',Y',Z');
% Generate solid object
subplot (2,2,2)
% hObj = tetramesh(T,ones(size(T)),'FaceAlpha',0.5,'EdgeColor','none','FaceLighting','phong');
hObj = tetramesh(T,ones(size(T)),'FaceAlpha',0.5,'EdgeColor','none','FaceLighting','gouraud');
light('Position',[-10 -10 10],'Style','local')
light('Position',[-10 -10 -10],'Style','local')
subplot (2,2,3)
% hObj = tetramesh(T,ones(size(T)),'FaceAlpha',0.5,'EdgeColor','none','FaceLighting','phong');
hObj = tetramesh(T,ones(size(T)),'FaceAlpha',0.2,'EdgeColor','none','FaceLighting','gouraud');
light('Position',[-10 -10 10],'Style','local')
light('Position',[-10 -10 -10],'Style','local')
subplot (2,2,4)
% hObj = tetramesh(T,ones(size(T)),'FaceAlpha',0.5,'EdgeColor','none','FaceLighting','phong');
hObj = tetramesh(T,ones(size(T)),'FaceAlpha',0.1,'EdgeColor','none','FaceLighting','gouraud');
light('Position',[-10 -10 10],'Style','local')
light('Position',[-10 -10 -10],'Style','local')
Kelly Kearney
el 1 de Oct. de 2021
The following example shows a relatively simple way to create patch surfaces that connect each circle to the adjacent one (assuming that all of your circles include the same number of vertices).
% Coordinates for 3 simple test circles
nv = 50;
th = linspace(0,2*pi,nv);
r = [10; 5; 6; 8];
z = [0; 1; 2; 1.5];
x = r.*cos(th);
y = r.*sin(th);
z = zeros(size(x))+z;
x = x'; y = y'; z = z';
% Calculate surface patch coordinates by connecting each
% circle to the adjacent one
ncirc = size(x,2);
[c0,v0] = ndgrid(1:ncirc-1, 1:nv-1);
cidx = c0(:) + [0 1 1 0 0];
vidx = v0(:) + [0 0 1 1 0];
idx = sub2ind(size(x), vidx, cidx);
xs = x(idx');
ys = y(idx');
zs = z(idx');
% Plot
hp = patch(xs, ys, zs, 'b');
view(3);
set(hp, 'facealpha', 0.8, 'edgecolor', 'none');
hold on;
plot3(x,y,z, 'k');
camlight
You'll probably have to play around with lighting and transparency, but this should be robust even if your circles overlap or reverse direction, as I've shown with the last two in this example.
Ver también
Categorías
Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!