Getting Points Inside Of A Polygon

  • Context: Undergrad 
  • Thread starter Thread starter twoski
  • Start date Start date
  • Tags Tags
    Points Polygon
Click For Summary

Discussion Overview

The discussion revolves around methods for determining whether points lie within a complex polygon, particularly focusing on algorithms that could be more efficient than ray tracing. The scope includes theoretical approaches and practical applications in gaming and graphics programming.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes using ray tracing to create a grid of points within a polygon and seeks a faster algorithm for point-in-polygon detection, especially for concave shapes.
  • Another participant mentions using background color to determine point inclusion and suggests bounding boxes to eliminate some points, noting that complexity increases for certain shapes.
  • A participant discusses the ray-casting method for point inclusion, expressing concerns that it may not be faster than ray tracing due to the necessary collision checks.
  • One contributor raises the issue of handling overlapping shapes and suggests using color intensity to differentiate shapes, which could be less noticeable to users.
  • Another participant proposes storing an internal array of pixels to optimize point checks, especially when many points are needed.
  • A participant reflects on their past gaming experience and mentions the shape fill method for colorizing areas as a useful technique.
  • One participant reiterates the ray-casting method and introduces the idea of using scratch memory to sample bits for point testing, suggesting the Flood Fill algorithm as a potential alternative once a point inside is identified.
  • Another participant shares links to resources for testing points inside triangles and polygons, indicating additional methods and references for further exploration.

Areas of Agreement / Disagreement

Participants express various methods and ideas without reaching a consensus on the best approach. Multiple competing views on techniques and their effectiveness remain present throughout the discussion.

Contextual Notes

Some methods discussed may depend on specific definitions of polygons or assumptions about their shapes. The effectiveness of suggested algorithms may vary based on the complexity of the polygons involved.

twoski
Messages
177
Reaction score
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: 873
Mathematics news on Phys.org
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.
 
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.
 
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.
 
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   Reactions: jedishrfu
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.
 
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K