smooth shading of patches in 3D - partially correct

10 visualizaciones (últimos 30 días)
Filip
Filip el 23 de Ag. de 2017
Comentada: Filip el 21 de Ag. de 2019
I am trying to render a nice 3d figure of a Voronoi cell by plotting the faces using the patch function and gouraud lighting to get smooth shading of the surfaces. The vertex normals are computed by a weighted average of the face (polygon) normals using the face areas as weights. It all looks relatively nice except that some faces do not have any light reflection. I cannot understand why I do not get the proper shading, and I would be very grateful any pointers to solve this.
Here is how it looks with the associated vertex normals drawn
and here is the code to produce it:
fig = figure();
ax = axes('Parent',fig);
p=patch('Faces',F,'Vertices',V);
p.Parent = ax;
hold(ax,'on');
p.FaceColor = [0.95 0.95 0.95];
p.VertexNormals = vnorm;
for n = 1:nqV
q=quiver3(V(n,1),V(n,2),V(n,3), vnorm(n,1), vnorm(n,2), vnorm(n,3) );
q.Color = [0.8 0.3 0.3];
q.LineWidth = 1.2;
q.MaxHeadSize = 2;
q.Parent = ax;
q.AutoScale = 'off';
end
view([-128 11])
axis equal
lighting gouraud
grid on
with matrices
F = [34 29 30 31 32 33 28 8 1 7
17 16 15 3 13 NaN NaN NaN NaN NaN
17 18 19 2 24 16 NaN NaN NaN NaN
13 17 18 5 11 NaN NaN NaN NaN NaN
7 1 19 18 5 NaN NaN NaN NaN NaN
16 24 25 14 15 NaN NaN NaN NaN NaN
25 24 2 22 NaN NaN NaN NaN NaN NaN
26 28 33 27 23 14 25 22 NaN NaN
31 30 6 21 NaN NaN NaN NaN NaN NaN
21 31 32 27 23 4 20 NaN NaN NaN
12 29 30 6 9 NaN NaN NaN NaN NaN
20 21 6 9 NaN NaN NaN NaN NaN NaN
33 27 32 NaN NaN NaN NaN NaN NaN NaN
22 26 8 1 19 2 NaN NaN NaN NaN
12 10 4 20 9 NaN NaN NaN NaN NaN
28 8 26 NaN NaN NaN NaN NaN NaN NaN
10 3 15 14 23 4 NaN NaN NaN NaN
34 11 5 7 NaN NaN NaN NaN NaN NaN
12 29 34 11 13 3 10 NaN NaN NaN];
V = [41.3411 42.6534 56.4570
42.9971 42.6986 56.0056
45.0957 42.6232 59.0728
43.0092 39.8638 59.3526
42.6463 44.4461 57.7151
42.1427 40.7134 60.4942
41.2465 44.0467 57.8011
41.5264 41.3264 56.3131
42.2348 40.7407 60.5345
44.1656 41.6457 60.0810
42.8749 44.4715 57.7761
42.5611 41.2097 60.7129
44.1996 44.2797 57.7430
44.5492 41.5642 57.9694
45.1375 42.5838 58.7361
44.6270 43.5925 57.2962
44.3424 44.0581 57.5101
43.1233 43.3174 56.4938
42.9432 42.7561 56.0245
42.8686 39.8425 59.4215
42.0284 39.7133 59.2071
42.9318 42.5213 56.0112
43.1946 39.8895 58.5593
44.5263 43.4475 57.1530
44.4736 41.7693 57.7335
41.6762 41.2894 56.2694
42.4125 39.7685 58.1382
41.5866 41.0063 56.4636
41.8281 41.6300 60.4530
41.9439 40.8349 60.4245
42.0070 39.7099 59.1804
41.9873 39.7061 58.9383
41.7631 40.2636 57.2521
41.4068 43.5440 58.8224];
vnorm = [-0.9742 0.0570 -0.2185
0.3383 0.0552 -0.9394
0.4967 0.4317 0.7529
0.6578 -0.6820 0.3196
-0.1656 0.8073 -0.5664
-0.2402 -0.6126 0.7530
-0.9892 0.1186 -0.0857
-0.9902 -0.1361 -0.0303
0.2504 -0.6009 0.7591
0.4696 0.2665 0.8417
0.0978 0.7705 0.6299
0.1726 0.5025 0.8472
0.2059 0.7654 0.6097
0.6904 -0.6060 -0.3951
0.9321 -0.3617 0.0181
0.8390 0.2851 -0.4635
0.4482 0.7058 -0.5487
-0.0528 0.6842 -0.7274
-0.1447 0.5425 -0.8275
0.2958 -0.7799 0.5516
0.0018 -0.9486 0.3166
0.4266 -0.4843 -0.7639
0.6181 -0.7014 -0.3551
0.7159 -0.0391 -0.6971
0.5699 -0.4910 -0.6589
0.3608 -0.5306 -0.7670
0.3938 -0.6983 -0.5977
-0.7569 -0.5513 -0.3510
-0.6932 0.3597 0.6245
-0.9805 -0.1564 0.1187
-0.9669 -0.2384 0.0911
-0.9626 -0.2614 0.0707
-0.7447 -0.5696 -0.3478
-0.6775 0.4064 0.6130];

Respuestas (3)

Mike Shives
Mike Shives el 19 de Ag. de 2019
Also interested in this

darova
darova el 19 de Ag. de 2019
Changed the script a bit
clc,clear
run data
p = patch('Faces',F,'Vertices',V);
set(p, 'FaceColor', [0.95 0.95 0.95])
grid on
hold on
q = quiver3(V(:,1),V(:,2),V(:,3), vnorm(:,1), vnorm(:,2), vnorm(:,3) );
hold off
set(q, 'Color', [0.8 0.3 0.3])
set(q, 'LineWidth', 1.2)
set(q, 'MaxHeadSize', 2)
set(q, 'AutoScale', 'off')
view([-128 11])
axis equal
lighting gouraud
light('Position',[0 -2 1])
It produces this:
img1.png
  8 comentarios
darova
darova el 21 de Ag. de 2019
Isn't that you wanted?
img1.png
Filip
Filip el 21 de Ag. de 2019
No. There is no smooth shading. I can't make myself more clearer than what I have already done.

Iniciar sesión para comentar.


Mike Shives
Mike Shives el 19 de Ag. de 2019
Filip.
I may not get the chance to look into it today, but I have a suspicion that if you manually specify the patch FaceNormals it might help. (I think the lighting may be relying on the VertexNormals.. which looks wrong.)

Categorías

Más información sobre Surface and Mesh Plots 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!

Translated by