I have a set of points + edges connecting pairs of them. There are enough edges so that one can triangulate the points by choosing a subset of the edges; That is exactly what I want to do - find a triangulation that uses the existing edges and does not add new edges that didn't exist in the original graph.
Is there existing code for doing that?
Related
I'm facing issues when trying to create voronoi regions in MATLAB and handle infinite vertices. I am relatively inexperienced in programming which I feel is hampering my ability to solve this problem.
I want to trace specific locations near the central nodes of the voronoi sub-polygons using the function inpolygon. I can not utilise the function if one of the vertices is Infinite (INF). Therefore, I wanted to create a grid around the voronoi split (As seen in image), and only consider the region within this grid, thereby neglecting the infinite vertices.
What I have done so far:
I already have a certain 100 pairs of Latitudes and Longitudes of nodes, around which I create a voronoi split using voronoi(x_coordinates, y_coordinates) function.
When I have to determine the various coordinates of the sub-polygons within this split, I use the
[V,C] = voronoin([x_coordinates, y_coordinates]);
Till now, this gives me all the of voronoi regions in V and all indexes of vertices for all sub-polygons (voronoi regions) in C.
Then I have implemented a function which uses inpolygon and takes x and y coordinates of the point that has to be traced within one of the voronoi regions. And here is where I am stuck. I am trying to implement a grid all around, but can not find the new intersecting vertices of the grid and the voronoi sub-region to find the new vertices of the voronoi sub-polygons.
Also, if there is any other way to achieve the same task, any help would be highly appreciated.
Many Thanks.
I want to generate a polyhedron which its vertices are specified. To this end, I use delaunayTriangulation command, but there is a problem and that is high number of triangular faces.So, is there any way to limitation of number of triangular faces? For example,I would like to generate a polyhedron by 8 triangular faces.
Thanks in advance.
My understanding of how a Delaunay triangle is created is that it is using the halfway point, on a lines to the nearest proximal neighbours, to nearest surrounding points to define the edge of the triangle surrounding a point. At its most basic to create 8 triangles you would need 8 points; you would have to accommodate the edge effects but you would have 8 facets or triangles. If you are specifying the vertices of the triangles instead of the central points you will probably get a lot more triangles that required and also may not be getting an appropriate depiction of the analysis you are looking for. Matlab has the capacity to control edge effects in a 2d depiction. HTH, Mark
I'm trying to get the Trajectory from Voronoi Diagram using the library voronoi from Matlab. I'm using this code:
vo = (all the obstacles from a binary picture, plotted in a figure), where:
vo(1,:) : x-axis points
vo(2,:) : y-axis points
Code:
figure; hold on;
plot(vo(1,:),vo(2,:),'sr');
[vx,vy] = voronoi(vo(1,:),vo(2,:));
plot(vx,vy,'-b');
Obtaining:
In other words, how can I separate all the useless lines from the real trajectory?
The distinguishing property of the useless lines in this case is that they contain at least one vertex inside the polygonal obstacles.
There are many ways you might choose to decide if a vertex satisfies this condition but given that the coordinates come from a binary image, one of the most straightforward might be to check if the vertex comes within a pixel's distance of any point in vo:
[~,D] = knnsearch(vo,[vx(:),vy(:)]);
inObstacle = any(reshape(D,size(vx)) < 1);
plot(vx(:,~inObstacle),vy(:,~inObstacle),'-b');
If you cannot rely on the obstacles being filled with pixels (e.g. they may be hollow) then you probably need to determine which pixels belong to the same obstacle (perhaps using kmeans or bwconncomp) and then eliminate Voronoi edges that intrude into each object's convex hull. For a given obstacle made up of the pixels in vo listed by the linear indices idx:
K = convhull(vo(idx,1),vo(idx,2));
inObstacle = inpolygon(vx,vy,vo(idx(K),1),vo(idx(K),2));
In part of an Artificial Neural Network matlab code, I want to find nearest points of two convex polygons.
I saw
dsearchn(X,T,XI)
command's description here, but that finds closest points between two sets of points, and polygons (like convexs) have infinites points.
So can you suggest any way/idea?
Notice: I'm using MATLAB 2014a. I have the coordinate of each convex's vertex point.
If you are not happy with what is provided by dsearchn, then, If I were you, I would do one of two following:
Find Nearest Neighbours on the vertices (for example which vertex of
polygon A is the NN of a given vertex of polygon B).
Pick a random point inside polygon A (you may want to compute the
convex hull of A, but you may skip that and take into account only
the vertices you know already). That random point is the query. Find
an NN of that point from the vertices of polygon B.
You may want to ask in Software recommendations for more.
Edit:
Another approach is this:
Create a representative dataset of polygon A. Set the size of the dataset yourself and fill it with samples of points that lie inside the polygon. Choose them uniformly randomly inside the polygon.
Then take a point of polygon B (either a vertex or a random point inside polygon B) and that's the query point, for which you will seek Nearest Neighbour(s) inside the representative dataset of polygon A.
Of course that's just an approximation, but I can't think of something else now.
Notice that you can of course do the same for polygon B.
With This File in File Exchange, I've find the solution.
With a little code modification, I have drawn a perpendicular bisector which I wanted. Of course, this way is time consuming.
I am trying to find the points with edge-adjacent Voronoi regions in a given dataset. I'm new to computational geometry, but from reading up online, it appeared that using the Delaunay tessellation would be an easy way to do this. This PDF in particular even has a lemma that states
Lemma 2.4 Two points of S are joined by a Delaunay edge iff their Voronoi regions
are edge-adjacent.
So, I found the delaunay tessellation of my dataset as
dt = delaunay(dataset); %using delaunayn() since dataset can be multidimensional
But now, when I plot this along with the voronoi diagram for this dataset, I find that the delaunay edges returned connect points whose regions are not actually edge-adjacent.
Here is the code I used to plot Voronoi and Delaunay together:
voronoi(dataset(:, 1),dataset(:, 2));
hold on;
dt = delaunayn(dataset);
triplot(dt, dataset(:, 1), dataset(:, 2), 'red');
And here is the output:
As an example of the problem, see the point X on the right end of the figure connected to point Y near the lower left corner.
Another example is in this SO question - the point 1 is connected to 2 and 3, even though they're not adjacent, and there doesn't seem to be any way 1 and 2 could share an edge even if extended to infinity. This question is actually what prompted me to test the delaunayn output with the above code.
Why is this happening, and how do I actually get the edge-adjacent neighbour regions that I need?
Note: For seeing the image in full size and clarity, please right click and choose 'View image' or similar.
As far as I can see (the quality of the diagram is not so good), the regions for X and Y should be adjacent below the plotted part. If you zoom out far enough, you should see them.
I.e. the edge where X and Y meet exists, but is just not shown on the plot.
The following diagram does not show the voronoi diagram outside of the plotting area, but how to find the intersection point described above (note, the bisector is not shown here):