ich habe eine Fläche , wie im Anhang sichtbar "Blau" ...eingerahmt mit den roten Eckpunkten x,y,
wo ich aber nicht die grünen Dreiecke mitberechnet und geplottet haben will die außerhalb der Blauen Grenzen liegen...
wie folgt die InputDaten :
Code:
>> [x, y]'
ans =
581.04475.18872.73670.43964.48978.59 1069.7956.75455.69286.32323.95265.14
Columns 7 through 12 1072.71145.61503.21439.71376.11164.4 248.68248.68269.85293.37302.78495.68
Columns 13 through 17 1150.3886.85893.9868.03578.68 490.98730.92770.91829.721067.3
% ::::::::::::::::: plot(x,y,'ro','Markersize',8,'Linewidth',2) hold on
plot(x, y, 'b-','Linew',1.5);
grid % :::::::::::::::::::::::::::::::::::::
tri = delaunay(x, y);
htr = triplot(tri, x, y,'g')
zur Veranschaulichung hängt die Ziel-grafik als jpg dran und noch die PDF, wo die Variablen im Workspace drin sind , auf die es mir ankommt ...
Könntet ihr mir eventuell paar tips geben, wie man die außerhalb liegenden grünen Dreiecke separat löschen kann ???
Vielleicht muß man vorher die Grenzen - Boundaries besser definieren,
damit bereits bei Delaunay nur die Dreiecke erzeugt und berechnet werden , die innerhalb der blauen Grenzen liegen ... ??
leider fehlt es mir daa in der Rübe ...
Vielen Danke vorab für Tips & Tricks, Zeit & Mühen..
Beste Grüße
stoxxii
Was man machen kann ist jedes Dreieck einzeln mit triplot() zu generieren. Dann kann man auch einzeln feststellen ob es innerhalb oder außerhalb der Grenze liegt. Um das zu machen kann man inpolygon() benutzten, allerdings muss man dafür erst Punkte vom Dreieck auswählen die auf jeden Fall außerhalb der Grenze liegen falls das Dreieck zum Teil außerhalb liegt. Mit inpolygon() sind alle Ecken immer teil des Polygons; Punkte die aber in der Nähe von den Ecken auf den Seiten des Dreiecks liegen sind allerdings eine gute Wahl.
x = [581.04475.18872.73670.43964.48978.591072.71145.61503.2... 1439.71376.11164.41150.3886.85893.9868.03578.68].';
y = [1069.7956.75455.69286.32323.95265.14248.68248.68269.85... 293.37302.78495.68490.98730.92770.91829.721067.3].';
% first figure: draw countour figure(1) plot(x,y,'ro','Markersize',8,'Linewidth',2) hold on
plot(x, y, 'b-','Linew',1.5);
grid
%% ANALIZE EACH TRIANGLE
% Here each triangle is analized on its own. The analysis consists in % setting two points on each side of the triangle. The points are set very % close to the corners, depending on a value "delta". Once the points are % set it is checked wether every corner lies inside the polygon, using the % function "inpolygon()". It is necessary to set the points at a certain % "delta" from the corner, because every corner lies inside the polygon, % even if the side does not.
% create set of triangles and permute them to plot one at the time
tri = delaunay(x,y);
tri = permute(tri,[3,2,1]);
% plot one triangle at the time
htr(i) = triplot(tri(1,:,i), x, y,'g');
% delta: distance of points from the corners
delta = 0.001;
% slope of the sides -- for vertical slopes: Inf
m = (htr(i).YData(2:3:end) - htr(i).YData(1:3:end))...
./(htr(i).XData(2:3:end) - htr(i).XData(1:3:end));
% x-sign of the points: sais wether point has to be on the positive or on % the negative side of the corner on the x axis
signx = sign(htr(i).XData(2:3:end) - htr(i).XData(1:3:end));
% x-values of the points
xq = [htr(i).XData(1:3:end) + signx(1:end)*delta...
htr(i).XData(2:3:end) - signx(1:end)*delta];
% y-sign of the points -- for vertical slopes: 0
signy = sign(xq - [htr(i).XData(1:3:end) htr(i).XData(2:3:end)]);
% sign for vertical slopes is computed here
signy_temp = [sign(htr(i).YData(2:3:end) - htr(i).YData(1:3:end))... sign(htr(i).YData(1:3:end) - htr(i).YData(2:3:end))].*(signy==0);
signy = signy + signy_temp;
% y-values of the points -- for vertical slopes: Nan
yq = [htr(i).YData(1:3:end) htr(i).YData(2:3:end)]...
+ [m m]*delta.*signy;
% y-values for vertical slopes is computed here
yq_temp = (isnan(abs(yq))|(abs(yq) == inf)).*... ([htr(i).YData(1:3:end) htr(i).YData(2:3:end)] + ...
signy*delta);
% infinite or nan values are set to 0 to be substituted
yq(isnan(yq)|(abs(yq) == inf)) = 0;
yq = yq + yq_temp;
% logical array: says for every triangle wether all points are inside % or outside
in(i) = logical(prod((inpolygon(xq,yq,x,y))));
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.