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#
Related
We're creating an app with unity where the user can position objects in the 3D space, along two axes (Z, X, so no height).
And there's a case where the object needs to align against other objects or the "outer canvas".
This is pretty similar to how Figma or Photoshop handles its "smart guides"/"alignment guides", here's an example on Figma, look at the "red lines":
Video version of this gif: https://imgur.com/WmaYuAr.mp4
But we're confused about how to approach/implement it. Not sure exactly how to do it. We tried implementing it using raycasts but with no success.
Where can I find resources to learn how to implement something similar to this? How could we approach it?
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.
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
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).
I've looked at many collision detection technique for a 2D game but I can't find exactly what I'm looking for. My game is a brickbreaker kind of game.
I've looked at pixel to pixel collisions style but it looks complicated for what i'm trying to do.
Is there an easier way?
I'm using XNA.
Thanks in advance.
Have you tried looking into Rectangle collisions ?
You declare a Rectangle on your sprites and check if they Intersect to test for a collision. It's the easiest way I know.
Look here for explanations on how to use it.
Hope this helps.
Here is the correct way to do it.
Tessellate both objects into a set of convex sub regions. This can be done as a pre-processing step.
For each combination of two sub regions from object A and object B, do the following comparison:
a. Construct a skewed prism in N+1 dimensional space. This is the extrusion of the convex subregion as it moved from its location at time=0 to time=n. If the object rotated, you're SOL as this will not be a convex region.
b. Use the Simplex algorithm to determine if there is a feasible intersection of the two convex sub regions. Alternately you could use the ellipsoidal method or an interior traversal LP algorithm.
c. If any of the pairs of convex sub regions intersect, then there is a collision.
... or you can use axis-aligned rectangles like everyone else. If you need to speed them up, use interval trees.