Polygon Triangulation c# - c#

I need to calculate triangles of a polygon. Polygon can contain holes. And Req an efficient way.
So I think I need Constrained Delaunay Triangulation.
I must do that in c#, only need calculation not drawing or something.
poly2tri seems good but idk its not working for me :S
Anyway I need help. How can I calculate that triangles?
(If your best offer is poly2tri, i can explain my problem on it)

Delaunay was not designed for this, use Ear Clipping instead.

I suppose my simple solution on github:gist (but it's rather old and probably not optimal).

Related

Slicing a 3D model?

I want to slice a 3D model relative to an infinite plane(In WPF). I'm checking if edges intersect with the infinite plane. If true, I'll create a new point at the intersection position, so I'm getting a couple of points that I want to generate a cap on so that the model is closed after slicing. For example, if this is the cross section, the result would be as follows:
Note: The triangulation ain't important. I just need triangles.
I also need to detect the holes as follows(holes are marked in red):
If it is impossible to do it the way I think(It seems to be so), the how should I do it? How do developers cap an object after being sliced?
There is also too much confusion. For example, The first picture's result may be:
What am I missing??
EDIT:
After some research, I knew one thing that I am missing:
The input is now robust, and I need the exact same output. How do I accomplish that??
In the past, I have done this kind of thing using a BSP.
Sorry to be so vague, but its not a a trivial problem!
Basically you convert your triangle mesh into the BSP representation, add your clipping plane to the BSP, and then convert it back into triangles.
As code11 said already you have too few data to solve this, the points are not enough.
Instead of clipping edges to produce new points you should clip entire triangles, which would give you new edges. This way, instead of a bunch of points you'd have a bunch of connected edges.
In your example with holes, with this single modification you'd get a 3 polygons - which is almost what you need. Then you will need to compute only the correct triangulation.
Look for CSG term or Constructive Solid Geometry.
EDIT:
If the generic CSG is too slow for you and you have clipped edges already then I'd suggest to try an 'Ear Clipping' algorithm.
Here's some description with support for holes:
https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
You may try also a 'Sweep Line' approach:
http://sites-final.uclouvain.be/mema/Poly2Tri/
And similar question on SO, with many ideas:
Polygon Triangulation with Holes
I hope it helps.
Building off of what zwcloud said, your point representation is ambiguous. You simply don't have enough points to determine where any concavities/notches actually are.
However, if you can solve that by obtaining additional points (you need midpoints of segments I think), you just need to throw the points into a shrinkwrap algorithm. Then at least you will have a cap.
The holes are a bit more tricky. Perhaps you can get away with just looking at the excluded points from the output of the shrinkwrap calculation and trying to find additional shapes in that, heuristically favoring points located near the centroid of your newly created polygon.
Additional thought: If you can limit yourself to convex polygons with only one similarly convex hole, the problem will be much easier to solve.

Searching intersection point of two splines in graph

I am stuck at this point. I am trying to find where two lines in graph intersects. I have 10 points for each spline, but they intersects between this points.
I am using c# graph. (System.Windows.Forms.DataVisualization.Charting.Chart chart2;)
Do you have an idea how to solve this?
Here is this situation. Points are measured manually so there is minimum posibility that it will intersetcs on this given points.
Refine the splines to the degree of precision you need and then intersect (straight) line pairs, as Matthew suggested. This can be done quite efficient if you chose the right data structure to store the line segments, so that it supports fast range queries (kd-tree perhaps?).
Doing it analytically is going to be really hard, I guess.
I found the solution, I used least squares theory and polynomial function to represent equation of curve and after that solve the equation. If anybody needs solution just write me.

Get diameter of circle in bitmap

My problem is following. I need precisely measure diameter of circles in bitmap.
I have Bitmap with several circles. Some of them are concentric. I need values of their diameters.
I tried OpenCV and EmguCV and their method HoughCircles. But this method find circles on the places where is are no circles (I tried a lot of combinations of input parameters). Ad if it finds them there is no case, when it found exatly same circle as in the bitmap. Their centers and diameters are different then circles on the original picture. So this method is only for some kind of game. Not for my purpose(precise measuring for industry).
Do you know some way or algorithm how to do it? (I prefer C#, but if it will be in pseudocode or different langueage, I will rewrite it)
Thanks in advance.
If you could detect circles, you may benefits from this opencv function findContours() in order to get all circles as contours, then you will be able easily to calculate their areas
Then, use this formula Area = pi*r^2 to calculate r.
diameter = 2*r
You are asking for an answer to a very hard problem. The hough algorithm is not a toy solution, but it is not appropriate for all machine visions circle detection situations. Human eyes are very good at such thing (if a bit imprecise). You basically need to know a lot more about your data to approach a robust solution.
Take a look at this dicussion about Hough Circle detection as well as this paper Hough Circle Transform for a deeper understanding of the limitations
You might also want to review this paper on the ant system for ideas on a different approach.
You also might want to read up on Morpological thinning as a possible pre-preprocessing step before Houghton
Best of luck

BoundingSphere intersection

my question should be simple (even if I can't find a way out).
When two BoundingSphere intersects they should share one or two points. I wanna know if there is any chance to know those points exactly (or approximately) or not.
I was thinking something like this:
-check if the spheres intersect
-calculate radius_1 distance from center_1 in the direction of center_2
-calculate radius_2 distance from center_2 in the direction of center_1
-substract the smaller to the larger and have that one as "collision" point
but since this sounds to me a little too tricky, I wanted to know if there is a simplier way to achieve this.
Hope to have made myself clear
Posting the same question on gamedev I got this answer.
It seems quite complete and it allowed me to understand things better and solve my problem.

How to cover a polygon with triangles

I'm using slimdx in c#, and my problem is a follows:
I have a list of vertices that forms a polygon, in linestrip format, and I need to transform it to a trianglestrip that covers the polygon.
I started with a center-of-mass calculation, however it only covers convex ones, and I need a general solution.
The final result should look smth like this:
Does anyone happens to know any algorithms for the issue?
Thanks.
There's ear clipping algorithm that is quite nice for your use case, an example can be found here:
Ear clipping c#

Categories