Triangle.NET | NET generates 2D Delaunay triangulations | Animation library
kandi X-RAY | Triangle.NET Summary
kandi X-RAY | Triangle.NET Summary
Triangle.NET generates 2D (constrained) Delaunay triangulations and high-quality meshes of point sets or planar straight line graphs. It is a C# port of Jonathan Shewchuk's Triangle software.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Triangle.NET
Triangle.NET Key Features
Triangle.NET Examples and Code Snippets
Community Discussions
Trending Discussions on Triangle.NET
QUESTION
I've been having issues with triangulating certain polygons with holes using Triangle.Net.
The issue seems to be certain circumstances where I define a hole using a contour and setting hole to 'true' (after first adding the outer contour, hole set to false). Polygon.Add(contour, true);
Triangle.Net then finds a point inside that hole through Point.FindInteriorPoint
and for reasons I don't know sometimes it finds a point that is on the very edge of that hole and the result is the only thing that gets triangulated is the hole, the rest of the polygon is ignored.
So for example. Two polygons with identical outer contours :
(3.5, 3.5), (-2.5, 3.5), (-2.5 -0.5), (-4.5, -0.5), (-4.5, -2.5), (3.5, -2.5)
Image1
But one has a hole defined as this contour:
...ANSWER
Answered 2020-May-17 at 18:21There are two different things going on here and, together, this makes the behavior confusing.
The first issue is the behavior of FindInteriorPoint. This method has some robustness problems and can find points that are on the contour boundary. I suspect you aren't using this fork of Triangle.NET that contains some robustness improvements that should yield good results especially on these simple cases.
Now, if you do specify a hole using a point that is on the boundary of the hole, what do we expect will happen? The answer is the results are random/unpredictable. Triangle locates the triangle in the final mesh containing the point identified as a hole and delete all the triangles it is connected to without crossing any constrained segments. Which side (using exact arithmetic) depends on the exact coordinates of the endpoints of the subsegment in the mesh which for a refined mesh will depend on rounding that occurs computing the extra vertices inserted. Your case doesn't have any refinement so the location really is exactly on the the segment. Triangle walks from a starting point towards the hole location until it finds a triangle containing the hole point: the arbitrary location of the starting point determines which side it will reach first and end up choosing. So if you have a different surrounding domain, you get a different (arbitrary) starting point and you can get a different result.
QUESTION
I've looked through what seems like every question and resource there is for Triangle.NET trying to find an answer to how to insert a vertex into an existing triangulation. The closest I've gotten was in the discussion archives for Traingle.Net where someone asked a similar question (discussion id 632458) but unfortunately, the answer was not what I was looking for.
My goal here is to make a destructible wall in Unity where, when the player shoots the wall, it will create a hole in the wall (like in Rainbow Six Siege).
Here's what I did for my original implementation:
- Create initial triangulation using the four corners of the wall.
- When the player shoots, perform a raycast, if the raycast intersects with the wall then add the point of intersection to the polygon variable and re-triangulate the entire mesh using that variable.
- Draw new triangulation on the wall as a texture to visualise what's happening.
- Repeat.
As you can see, step 2 is the problem.
Because I re-triangulate the entire mesh every time the player hits the wall, the more times the player hits the wall the slower the triangulation gets as the number of vertices rises. This could be fine I guess, but I want destructible walls to play a major role in my game so this is not acceptable.
So, digging through the Triangle.Net source code, I find an internal method called InsertVertex
. The summary for this method states:
Insert a vertex into a Delaunay triangulation, performing flips as necessary to maintain the Delaunay property.
This would mean I wouldn't have to re-triangulate every time the player shoots!
So I get to implementing this method, and...it doesn't work. I get an error like the one below:
NullReferenceException: Object reference not set to an instance of an object TriangleNet.TriangleLocator.PreciseLocate (TriangleNet.Geometry.Point searchpoint, TriangleNet.Topology.Otri& searchtri, System.Boolean stopatsubsegment) (at Assets/Triangle.NET/TriangleLocator.cs:146)
I have been stuck on this problem for days and I cannot solve it for the life of me! If anyone who is knowledgeable enough with the Triangle.NET library would be willing to help me I would be so grateful! Along with that, if there is a better alternative to either the implementation or library I'm using (for my purpose which I outlined above) that would also be awesome!
Currently, how I've set up the scene is really simple, I just have a quad which I scaled up and added the script below to it as a component. I then linked that component to a shoot raycast script attached to the Main Camera:
What it looks like in Play Mode.
The exact Triangle.Net repo I cloned is this one.
My code is posted below:
...ANSWER
Answered 2020-Feb-24 at 20:21Great news! I've managed to fix the issue. InsertVertex()
doesn't actually add the new vertex to the list of vertices! So this means that when it tried to triangulate, it was trying to point to the new vertex but it couldn't (because that vertex wasn't in the list). So, to solve this, I just manually add my new vertex to the list of vertices in the mesh, before calling InsertVertex()
. Note: When you do this, you also need to manually set the vertex's id. I set the id to the size of the list of vertices because I was adding all new vertices to the end of the list.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Triangle.NET
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page