Calculate approximate outline from polygon points - math

I have a series of points that make up a polygon (the green dots below), these are connected with straight lines to make the polygon (the blue lines). I want to calculate the red lines, I've tried a few approaches around scaling the points and the lines but they always ended up with intersecting red lines which I don't want.
The green dots/blue lines polygon is drawn by the user so it could be any non-intersecting polygon.
Is it possible to calculate the red line, even approximately?
(If the red line had to go into the channel on the top of the polygon that would fine)

Related

Find gap between two non-overlapping polygons

I want to identify the gap between two non-overlapping polygons as a new polygon. As displayed in the image below, the comparison will be between polygons A and C, and the result should be the black area (gap) between them. For display purposes the gap area is highlighted with a red line. Any ideas on how to approach this problem ?
I tried using boolean clipping operation in c++, such as difference and exclusiveOr, but given that the polygon where non intersecting the results where not the gap between them.

How to detect whether a circle and a polygon overlap?

I am implementing a function that can detect whether a circle and a polygon are overlapping or not.
I have all the points of the polygon and I know the center points and radius of the circle.
There I check two scenarios:
polygon vertices are inside the circle
circle center is inside the polygon
But there are other scenarios in which a circle and a polygon are overlapping, as shown in the attached image. Can anyone suggest validation for finding the intersection?
Here is a possible approach.
If one of the polygon vertices is inside the circle, there is overlap.
If the the circle center is inside the polygon, they overlap. Note that this test is not trivial for non-convex shape. For example consider a polygon similar to a thin spiral.
Otherwise, for every edge (a,b) of the polygon:
Find p, the projection of the circle center to the line (a,b).
If the distance of p to the circle center is larger than the radius, there is no overlap for this edge.
Otherwise, if p is between a and b (so p_x between a_x and b_x, and also p_y between a_y and b_y, to include the case of horizontal and vertical edges), then there is overlap for this edge, otherwise not.

Thick line intersections

I am trying to calculate the intersection between 'thick' line segments. That is, lines which, on screen, have quite a thick stroke. This is because they may occasionally need to intersect but in reality lie parallel with either other without their actual centre lines intersecting.
The solution I have at the moment is to treat them as rectangles, which means treating each side as a line segment and testing them all sides of one rectangle against all sides of the other rectangle.
Is there a better way?

Fill gaps in edge of a polygon

I'm using pygame to draw polygons but when the line is too thick, there are gaps in the edges of the polygon. I want these gaps to be filled. The solution I found was to draw a filled polygon with 4 points in all the gaps as you can see on the image below. But I don't know how to find the 4 points of the polygon and that's my question. Also if you can find a better solution that would be great.
Note: The polygon isn't always regular, it's just made from many points. Also it's alright if your solution is not in python.
If your polygon has no acute angles (where direction changes by more than 90°),
at each corner point, extend both lines by (lineWidth/2)*tan(angle). The angle is the amount of direction change, not the inner angle between the segments.
If you do have acute angles, it gets more complicated. The line segments can no longer be drawn as rectangles and you must only extend the 'outer' edge of the polygon. The formula for that is the same.
You can extend lines so that they can fill the gap. Although picture
is not good, it may be enough to visualize the idea.

How to triangulate from a Voronoï diagram?

I computed a Voronoï diagram from a set of point (with Boost.polygon).
I try to find a Delaunay triangulation, connecting each cell center for each Voronoï edge, but I miss some edges.
In the following image, the red dots are my initial points, the blue lines are the Voronoï edges (I ignored infinite edges), and the green lines are the triangulation edges (on green edge for each blue edge, connecting two cell origins).
We can see that diagonal edges are missing. What am I missing?
4 Delaunay vertices lie on a common circle, this is a degenerate situation. Shift the points a little and you will recognize the problem.

Resources