1 view (last 30 days)
Marc Laub on 29 May 2020
Hey guys,
I have following problem:
I created a kind of voronoi mesh and I now know the position of all vertices and which vertices belong to which polygon.
I know want to treat the vertices and the polygons as classes with handels and link them, so that each vertice knows which are its adjacend vertices and its adjacend polygons and each polygon knows which are the adjacend polygons and the vertices that define their borders.
My classes look like following:
classdef Vertex < handle
properties
position;
neighbour_vertex;
end
methods
function v = Vertex(pos)
v.position = pos;
v.neighbour_vertex = Vertex.empty(0,0);
end
v.neighbour_vertex(end+1)=neighbour;
neighbour.neighbour_vertex(end+1)=v;
end
end
end
classdef Polygon < handle
properties
rho
end
methods
function p = Polygon(rho)
p.rho=rho;
end
for i=1:length(vertex)
end
end
continue
else
end
end
end
end
end
end
I linked all object stogether as follows:
pos = vertices;
vertex = Vertex.empty(size(pos,1),0);
polygon=Polygon.empty(size(polygons,1),0);
for i = 1: size(pos,1)
vertex(i) = Vertex(pos(i,:));
end
for i=1:length(edge)
v1=edge(i,1);
v2=edge(i,2);
end
rhos=10^12*random('unif',0.9,1.1,length(polygons),1);
for i=1:size(polygons,1)
polygon(i)=Polygon(rhos(i));
end
for i=1:size(polygons,1)
end
for i=1:length(polygon)
end
But it doesnt work as planned. Since I find the polygons that are neighbours of a specific polygon, by looking for the already correctly linked vertices of that specific polygon and by looking for the adjacend polygons of those vertices, I double link them.... and since the polygon itsself is a adjacend polygon of its own vertices I link the polygon to itsself which I also do not want.
I got rid of the last point by the first expression in the if statement in the link p2p function in the polygon class, but the second statement that should prevent the double linking does not work...
How can i check if an object that i want to link to another object is already linked to that object?
Best regards
Marc