WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Anzahl der Punkte einer Triangulierung ändern

 

wishToBeAsWiseAsH.Arendt
Forum-Newbie

Forum-Newbie


Beiträge: 5
Anmeldedatum: 29.03.20
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 08.04.2020, 09:50     Titel: Anzahl der Punkte einer Triangulierung ändern
  Antworten mit Zitat      
Hallo liebe Matlabfreunde,

ich habe folgendes Problem und bitte um Hilfe.

Gerne möchte ich die Anzahl der Punkte innerhalb meiner bedingten Triangulierung erhöhen. Dies soll nicht durch eingelesene Punkte realisiert werden.

Hier mein Code:

Code:

X = [-1 1; 1 3; 2 2; 0 0; 2 0; 5 -3; 4 -4];
C = [1 2; 2 3; 3 4; 4 5; 5 6; 6 7; 7 4; 4 1];
dt = delaunayTriangulation(X, C);
figure(1)
triplot(dt);
xlabel('Constrained Delaunay triangulation', 'fontweight','b');
% Plot the constrained edges in red
hold on;
plot(X(C'),X(C'+size(X,1)),'-r', 'LineWidth', 2);
axis on
%axescenter
hold off;

load coordinates2.txt;
coordinates = coordinates2(:,2:end);
x = coordinates(:,1);                          % x-Koordinaten der Punkte
y = coordinates(:,2);  
%% 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]);

for i = 1:length(tri)
   
    % 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))));
   
end

%% PLOT ONLY INSIDE TRIANGLES

% outside triangles are removed using logical array "in"
tri = permute(tri(:,:,in),[3,2,1]);

% second figure: no outside triangles
figure(2)
hold on
htr = triplot(tri, x, y,'g');
plot(x,y,'LineWidth',2) % polygon
axis equal

 



Vielen Dank!

coordinates2.txt
 Beschreibung:

Download
 Dateiname:  coordinates2.txt
 Dateigröße:  53 Bytes
 Heruntergeladen:  161 mal
bedingteTriangulierung.png
 Beschreibung:

Download
 Dateiname:  bedingteTriangulierung.png
 Dateigröße:  13.07 KB
 Heruntergeladen:  159 mal
Private Nachricht senden Benutzer-Profile anzeigen


wishToBeAsWiseAsH.Arendt
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 5
Anmeldedatum: 29.03.20
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 08.04.2020, 10:36     Titel:
  Antworten mit Zitat      
Ich dachte vielleicht könnte ich mit alphaShape arbeiten und die Anzahl der Regionen setzen, aber da sind wohl nur die disjunkten Bereiche gemeint.
Auch wenn ich am Winkel herumschraube bekomme ich leider nicht mein gewünschtes Ergebnis.

Heißt das also, dass der einzige Weg zum Ziel eine gigantische seperate Datei ist, welche eingelesen werden muss?? Sad Ist das nicht unprofessionell?
Private Nachricht senden Benutzer-Profile anzeigen
 
wishToBeAsWiseAsH.Arendt
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 5
Anmeldedatum: 29.03.20
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 08.04.2020, 13:13     Titel:
  Antworten mit Zitat      
Ok. Nächster Ansatz. Das folgende Programm prüft die Länge der Kanten und teilt diese gegebenenfalls. Wie bekomme ich bitte die Kanten innerhalb des Gebiets? Optimal wäre eine Ausgabe in Form von den "nodes".

Viele Grüße

Code:


function shp = Diskretisierung()

% Plot der Geometrie mit FEM-Gitter
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Variablen
%      coordinates.txt - Datei der Punkte
%      nodes.txt       - Datei der Elemente (verbundene Knoten)
%
% Erklärung: coordinates [Knotennummer x-Pos y-Pos]
%            nodes [Elementnummer node1 node2 node3]
%--------------------------------------------------------------------------
%  Input
%--------------------------------------------------------------------------
load coordinates4.txt
coordinatesNew = coordinates4(:,2:end);
load nodes4.txt;
nodesNew = nodes4(:,2:end);
load edges4.txt;
%--------------------------------------------------------------------------
anzElemente = length(nodes4);                  % Anzahl der Elemente
anzNode = length(coordinatesNew);                % Anzahl der Nodes
anzNodElement = size(nodes4,2);                 % Anzahl der Nodes pro Element

%--------------------------------------------------------------------------
% Ermittlung der Kantenlänge, Teilung der Kante und Einfügen einer neuen
% Verbindung
h_max = 1;
for i=1:anzNode-1
    kantenlaenge(i) = length_edge(coordinatesNew(i,:),coordinatesNew(i+1,:));
    if kantenlaenge(i)>h_max
        [coordinates, edges, nodes]=
split_edges(coordinatesNew,edges4,h_max,nodesNew);
    end
end
x1 = coordinates(:,1);                          % x-Koordinaten der Punkte
y1 = coordinates(:,2);                          % y-Koordinaten der Punkte
figure(1)
triplot(nodes,x1,y1);
title('Finite Element Mesh');
axis on;
xlim([-5 5]) % Bereich für x Achse
ylim([-4 4]) % Bereich für y Achse
axescenter
end
 


Kanten splitten Code:

Code:

function [coordinates, edges,nodes] = split_edges(coordinates,edges,h_max,nodes)
[edges_start, edges_end] = find(edges);

cnt_edges =size(edges_start,1);  % Anzahl der Kanten
cnt_points =size(coordinates,1); % Anzahl der Punkte

edges =sparse(cnt_points,cnt_points);

 while~isempty( edges_start)
    % aktuelle Kante  steht  in  edges_start/end an Pos 1
    length_act_edge = length_edge(coordinates(edges_start(1),:),coordinates(edges_end(1),:));
    if length_act_edge  <= h_max
        % Kante  kurz  genug
        edges(edges_start(1),edges_end(1)) = 1;
    else
        % Kante  zu lang
        cnt_points =ceil(length_act_edge / h_max);  % Anzahl der neuen Punkte, welche auf der Strecke liegen. Bsp. Länge 2.8; h_max=1; Ergebnis 3                                                    
        a =  coordinates(edges_start(1) ,:);
        b =  coordinates(edges_end(1) ,:);
        coordinates = [coordinates; a + 1/ cnt_points * (b-a)];
        size_coordinates =size(coordinates ,1);
        edges(size_coordinates ,  edges_start(1)) = 1;
        for i = 2 : cnt_points -1
            coordinates = [coordinates; a + i/cnt_points * (b-a)];
            edges(size_coordinates , size_coordinates) = 1;
            size_coordinates = size_coordinates+1;
        end
        edges(size_coordinates ,  edges_end(1)) = 1;
    end
    edges_start(1) = [];
 end
 edges_end(1) = [];
end
 


Länge der Kante:

Code:

function [edge_length] = length_edge(a,b)
    edge_length =sqrt((a(1)-b(1))^2 + (a(2)-b(2))^2);
end
 


nodes4.txt
 Beschreibung:

Download
 Dateiname:  nodes4.txt
 Dateigröße:  43 Bytes
 Heruntergeladen:  164 mal
edges4.txt
 Beschreibung:

Download
 Dateiname:  edges4.txt
 Dateigröße:  139 Bytes
 Heruntergeladen:  161 mal
coordinates4.txt
 Beschreibung:

Download
 Dateiname:  coordinates4.txt
 Dateigröße:  59 Bytes
 Heruntergeladen:  171 mal
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

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
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

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.