problem with the patch function Warning: Error creating or updating Patch "Error in value of one or more of the following properties: Faces Vertices Values in Faces must lie within the range, 1 and number of vertices"
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hallo people
I have been using Matlab for a week and have the task of programming a 3D figure. The figure must consist of several small figures and I have already managed to program one small figure, but I have difficulty adding a second small figure. I keep getting an error: Warning: Error creating or updating Patch
Error in value of one or more of the following properties: Faces Vertices
Values in faces must lie within the range, 1 and number of vertices. I will be very grateful to you if you can help me. I apologize for my bad english.
clear all
clc
P1 = [1 0 0];
P2 = [2 0 0];
P3 = [2.5 1 0];
P4 = [2 2 0];
P5 = [1 2 0];
P6 = [0.5 1 0];
P7 = [1 0 9];
P8 = [2 0 9];
P9 = [2.5 1 9];
P10 = [2 2 9];
P11 = [1 2 9];
P12 = [0.5 1 9];
P13 = [1.5 1 12];
Hauptobjekt.Ecken= [P1;P2;P3;P4;P5;P6;P7;P8;P9;P10;P11;P12;P13]
P14 = [0.5 1 0];
P15 = [0.5 1 7];
P16 = [-2.5 1 0];
P17 = [0.6 0.8 0];
P18 = [0.6 0.8 7];
Fluegel.Ecken1 = [P14;P15;P16;P17;P18]
F1 = [1 2 8 7 1 1];
F2 = [7 1 6 12 7 7];
F3 = [12 6 5 11 12 12];
F4 = [5 11 10 4 5 5];
F5 = [4 10 9 3 4 4];
F6 = [3 9 8 2 3 3];
F7 = [1 2 3 4 5 6];
F8 = [7 8 9 10 11 12];
F9 = [7 8 13 7 7 7];
F10 = [8 9 13 8 8 8];
F11 = [9 10 13 9 9 9];
F12 = [10 11 13 10 10 10];
F13 = [11 12 13 11 11 11];
Hauptobjekt.Flaechen = [F1;F2;F3;F4;F5;F6;F7;F8;F9;F10;F11;F12;F13]
F14 = [14 16 15];
F15 = [16 15 18];
F16 = [16 14 17];
F17 = [16 17 18];
Fluegel.Flaechen1 = [F14;F15;F16;F17]
plot3(0,0,0)
grid on
patch('Vertices',Hauptobjekt.Ecken,'Faces',Hauptobjekt.Flaechen,'FaceColor','red')
patch('Vertices',Fluegel.Ecken1,'Faces',Fluegel.Flaechen1,'FaceColor','red')
axis equal
a= 15;
axis ([-a a -a a -a a])
1 Kommentar
VBBV
am 12 Dez. 2020
For every face, it requires a pair of vertices. You have 15 faces and only 13 pair ofvertices for first patch (4 vertices less) For second patch you have 12 faces but 13 pairs of vertices ( one extra )
Antworten (1)
Walter Roberson
am 12 Dez. 2020
For the second patch you ask for 5 edges, and you ask for 4 faces. However the face data you pass in uses vertice numbers up to 18, even though there are only 5 vertices for the patch.
When you add a second patch, the new vertices do not get added on to a global list of vertices, and you do not use vertex numbers relative to a global list of vertices. Instead each numbering is relative to that patch() only.
Note: in your situation you only need one patch object. Put in all 18 vertices. Put in all 17 of the faces, using the numbering you have.
The only adjustment you need to make to put everything into one patch() is to pad all of the face lists to the same number of columns. Pad the shorter rows with nan. So you would have a bunch of faces that have 6 numeric vertices and some that have a smaller number and then several nan.
When you do that, get rid of those duplicate vertices
F1 = [1 2 8 7 nan nan];
F2 = [7 1 6 12 nan nan];
your F9 onwards would have three numeric vertices followed by 3 nan.
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!