Getting Points Inside Of A Polygon

In summary, the conversation discusses different methods for determining if a point falls within a complex polygon shape. Some suggestions include using ray tracing, background color, bounding boxes, and collision checking. There is also mention of using a fill algorithm or referencing mathematical resources for solving the problem. The main focus is on finding a faster and more efficient way to detect if a point is inside a concave polygon.
  • #1
twoski
181
2
Let's say we have a somewhat complex polygon shape.

fNmZ4fZ.png


We know the list of 2d vectors that make up its border loop.

Now let's say i want to create a list of points within this polygon. Currently i am using ray traces to create a grid of points that fall within the polygon. I'm certain there is a better and faster way to achieve this without using raytraces though. Does anyone know of an algorithm to detect whether a point falls within a polygon which may be concave?
 

Attachments

  • fNmZ4fZ.png
    fNmZ4fZ.png
    3.3 KB · Views: 741
Mathematics news on Phys.org
  • #2
When I did games ages ago, I would use background color to determine if a point was inside.

Another trick would be bounding box to eliminate some points. For others it gets trickier.
 
  • #3
I have read about one approach where you draw a ray from a given point to the right then count how many times it collides with a polygon edge. If the number is odd, it's inside. If it's even, it's outside. The issue with this approach, i think, is that it wouldn't be any faster than my current raytracing since you still have to do a fair bit of collision checking with the line.
 
  • #4
Yes also what do you do about shapes within shapes or shapes overlapping shapes. That’s why I liked the color pixel approach. You could subtly adjust the color value to make each shape unique or maybe its intensity value.

People won’t notice subtle changes.
 
  • #5
You don't need to modify the output for the user, you can store an internal array of pixels if that is helpful for the game. If you need many points it might save some computing time.
 
  • Like
Likes jedishrfu
  • #6
Great idea @mfb

My gaming experience is from the days of the C64 where memory was more constrained and pixel checks were somewhat common in Basic programming.

Also the shape fill method was available to do the tough work of colorizing the area.
 
  • #7
twoski said:
I have read about one approach where you draw a ray from a given point to the right then count how many times it collides with a polygon edge. If the number is odd, it's inside. If it's even, it's outside. The issue with this approach, i think, is that it wouldn't be any faster than my current raytracing since you still have to do a fair bit of collision checking with the line.
Does it help if you actually draw the polygon perimeter in scratch memory? You could then sample a byte - or even a quadword - at a time to see if the ray has a bit set in the sample.

If you have a GPU available in the system there may even be a Call to do the testing.

Something that may lead to a different approach to the problem is the Flood Fill algorithm. Once one point is found inside the polygon, all the others are findable.
 
  • #8

1. How do you determine if a point is inside of a polygon?

To determine if a point is inside of a polygon, you can use the ray-casting algorithm. This involves drawing a line from the point to a point outside of the polygon and counting the number of times the line intersects with the edges of the polygon. If the number of intersections is odd, the point is inside the polygon. If it is even, the point is outside the polygon.

2. Can a point be on the edge of a polygon and still be considered inside?

No, a point on the edge of a polygon is considered to be outside of the polygon. This is because the ray-casting algorithm counts the number of intersections with the edges, and a point on the edge would only have one intersection, making the total number of intersections even.

3. What happens if the polygon is self-intersecting?

If the polygon is self-intersecting, the ray-casting algorithm may not work properly. It may result in an incorrect determination of whether a point is inside or outside of the polygon. In this case, a different algorithm, such as the winding number algorithm, may need to be used.

4. Is there a limit to the number of points that can be inside a polygon?

No, there is no limit to the number of points that can be inside a polygon. As long as the point is within the boundaries of the polygon, it is considered to be inside.

5. Can the shape of the polygon affect the accuracy of determining points inside?

Yes, the shape of the polygon can affect the accuracy of determining points inside. For example, if the polygon has narrow or sharp corners, the ray-casting algorithm may not work properly and result in incorrect determinations. In these cases, alternative algorithms may be necessary to accurately determine points inside the polygon.

Similar threads

Replies
1
Views
1K
  • General Math
Replies
7
Views
2K
Replies
4
Views
3K
  • General Math
Replies
33
Views
2K
Replies
3
Views
1K
  • Special and General Relativity
Replies
5
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
307
Replies
46
Views
2K
  • Quantum Interpretations and Foundations
Replies
12
Views
925
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
Back
Top