Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Design] Hit Test for nodes / arrows #14

Closed
ZhangMenghe opened this issue Jul 14, 2017 · 0 comments
Closed

[Design] Hit Test for nodes / arrows #14

ZhangMenghe opened this issue Jul 14, 2017 · 0 comments
Labels

Comments

@ZhangMenghe
Copy link
Owner

ZhangMenghe commented Jul 14, 2017

There are several ways to determine whether a point is inside polygon.
See wiki
Also, bounding box could used.
Roughly, the following methods could be applied:

  1. The axis-aligned minimum bounding box (or AABB) bounding box

  2. Object oriented minimum bounding box( OBB) see tutorial

  3. Ray-casting

4.Winding number algorithm (more precise but costly)

5.Just let the GPU do all the work for you.Use glReadPixel()

Create a painting surface that is off screen (so you can paint into it, without it appearing anywhere on the screen). Fill it completely with the color black. Now let OpenGL paint your polygon (or even all of your polygons if you just want to test if the point is within any of them, but you don't care for which one) into this drawing surface and fill the polygon(s) with a different color, e.g. white. To check if a point is within the polygon, get the color of this point from the drawing surface. This is just a O(1) memory fetch. If it's white, it's inside, if it's black, it's outside. Easy, isn't it? This method will pay off if you have very little polygons (e.g. 50-100), but a damn lot of points to test (> 1000), in which case this method is much speedier than anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant