I found some solutions to find the intersection between the circle and 1 triangle.
I am searching for a solution to find a more general solution, to find the area of the circle overlapped by the polygons present in the plan.
No 2 polygons intersect each other nor self-intersect.
A circle can be intersected (overlapped) by multiple polygons.
I would appreciate a C# solution.
Triangulate your polygons.
For each triangle i, compute the intersection area of your circle and triangle i. Call it A[i].
(You said you know how to do this part.)
The area of the intersection between your circle and your polygons is sum(A[i] for all triangles i).
Related
I would like to ask if it is possible to generate and draw a circle or ellipse using a linerenderer based on two points in the scene. Specifically, these are the vertices of the mesh. For example, I would like to draw a circle / ellipse around the neck of a given humanoid.
I need something like this:
I need this circle to enlarge and shrink based on the properties of the blendshapes. If I widen the neck with blendshape, I need this circle to enlarge as well. I can draw this circle by finding the id of all the vertices around the neck and entering these vertices into the LineRenderer. But it's a very impractical way that I don't want to use. So I would like to ask if it is possible to draw such a circle that would be connected only to two points and not to all / many.
I will be very grateful for any advice.
EDIT:
I was hoping that it would be enough to connect 4 vertices in the worldspace using LineRenderer, where I would get a drawn square. And I was hoping that some rounding would be used on the edges of this square to create an ellipse or circle. For a better idea, I also added a picture to describe what I thought would be enough to use.
I want to find the "visible" area of multiple overlapping polygons.
Let's say I have a Polygon polygonA and let the area be 100%
List<Vector2> polygonA; // points CW
Now I have another Polygon Inside polygonA which is polygon1(green) and its area is easy to calculate for now Let say the area of polygon1 is area_p1 %
List<vector2> polygon1; // points CW
Now I have another polygon polygon2(red) inside polygonA that overlaps polygon1 so now the area of polygon1 is changed. for now, the area% of red is easy to calculate but then some other polygon will overlap red polygon and it keeps going on.
List<vector2> polygon2; // red
So now how do I calculate the area % of visible color inside the polygonA.
I think a Clipper.cs could help but I can't find a way to figure it out in unity.
Rectangle Possibilities
I am trying to figure out if 2 rectangles that are rotated are intersecting.
The image(Rectangle Possibilities) shows examples of intersecting rectangle possibilities. The information that I know about each rectangle is the 4 vertices.
Rotate the two rectangles so that one becomes axis parallel, and check non-interference of the two axis-aligned bounding boxes. Then repeat with the second. This is necessary and sufficient to guarantee no overlap.
Powerfule method of checking whether two convex polygons do intersect is using Separating Axes Theorem. Yet more description.
It is rather simple (and fast) for rectangles.
I know 3 points in a 3D plane. Two points are the ends of a diagonal and an other one which is random point on the plane. How can I calculate the two other points of a rectangle from the known diagonal line? (Later I will use the points to calculate the perimeter of the rectangle in C#.)
There's no single right answer. All you can calculate using a diagonal and a random point on the plane is a whole sets of possible answers.
Imagine rotating the diagonal to create a circle - now every second line inscribed in that circle and going through the center can be the second diagonal. The only limit is your third point.
Since you know the end points of the diagonal, you can calculate the length of the diagonal; from there you can determine the rectangle side length; having diagonal coordinates and the side length, you can determine the other two points of the rectangle using add/subtraction.
I have an animated model that's spinning.
I want to hide/not draw any part of the model that's Y<0
what are the ways I can do it?
ideas:
1) draw a giant rectangular box right below y=0
2) tweak the camera matrix so that y<0 is outside of clipping plane (but i have no idea how)
can someone point me into the right direction? =)
A purely mathematical approach:
Don't draw the polygons whose y's are all less than 0.
Draw the polygons whose y's are all greater than or equal to 0.
Clip the rest of the polygons with the y=0 plane and draw them.
If the polygons making up the model are triangles, clipping them is pretty trivial. You need to clip the two sides intersecting with the y=0 plane and replace the original vertices whose y's are less than 0 with the intersection points of those two sides with the clipping plane.
Use the line equations:
(x-x1) = (x2-x1)*(y-y1)/(y2-y1)
(z-z1) = (z2-z1)*(y-y1)/(y2-y1)
where 1 and 2 are the vertices of the side being clipped by the y=0 plane. Substitute their coordinates (x1, y1, z1, x2, y2, z2) and y=0 into the equations to get x and z of the intersection point. Use this point's coordinates instead of vertex 1's or 2's (whichever has y < 0).
If the polygons are texture-mapped, you'll need to recalculate the texture coordinates for the vertices that you got from the clipping. You do that in the same fashion.
It sounds like you need to introduce MSDN Bounding Frustum
Here is a good tutorial from Nic's GameDev Site.