Browse Search Popular Register Upload Rules User list Login:
Search:
Point Is Inside Object Detector

Image:
screenshot of the scene

Author: s_noonan

Group: Default

Filesize: 58.87 kB

Date added: 2023-06-16

Rating: 5.6

Downloads: 469

Views: 212

Comments: 4

Ratings: 2

Times favored: 0

Made with: Algodoo v2.1.0

Tags:

Scene tag

Uses ray casting method. Kilinich code modified to remove memory leak.

Rev A: Added scene.my.check4mouseOver(entityID) which will check any shape.
Rev B: Added _boundingRadius for improved performance.
Rev C: Recognizes more objects.

Tool
Last edited at 2025/04/18 11:36:14 by s_noonan
Please log in to rate this scene
edit
Similar scenes
Title: The graph ends here...
Rating: 5
Filesize: 15.26 kB
Downloads: 1232
Comments: 0
Ratings: 1
Date added: 2019/01/14 18:32:34
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Smoke Detector
Rating: 6.1111
Filesize: 55.42 kB
Downloads: 1107
Comments: 4
Ratings: 3
Date added: 2010/06/04 19:06:05
Made with: Phun
Rating: rated 6.1
download
Title: Object Detector
Rating: 5
Filesize: 23.32 kB
Downloads: 430
Comments: 0
Ratings: 1
Date added: 2010/12/20 13:35:17
Made with: Algodoo before v1.8.5
Rating: rated 5
download
Title: Object Crusade Day 5
Rating: 5
Filesize: 2.11 MB
Downloads: 677
Comments: 7
Ratings: 1
Date added: 2015/09/14 17:43:24
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Smoke Detector
Rating: 5
Filesize: 14.03 kB
Downloads: 549
Comments: 0
Ratings: 1
Date added: 2010/06/05 08:07:32
Made with: Phun
Rating: rated 5
download
Title: Advanced Object Detector Screen Tech
Rating: 5.625
Filesize: 52.7 kB
Downloads: 755
Comments: 7
Ratings: 2
Date added: 2014/12/26 20:07:33
Made with: Algodoo before v1.8.5
Rating: rated 5.6
download
This scene is a response to:
Title Author Rating Downloads Comments Date added
Point in polygon detection(winding number) ezpz(fib)5 5 (1 vote) 1101 9 2023/06/15 08:19:33
show grid
I can cut up the box and the polygon with the knife tool and each smaller piece still detects my cursor by changing color, but not so with the circle.

It's actually kinda fun to do that!
How does your code detect the line intersections and where does the ray start? this method seems more reliable.
Q: How does your code detect the line intersections and where does the ray start?
A: It's Kilinich's code. It works as follows:

count := 0
foreach side in polygon:
. . . . if ray_intersects_segment(P,side) then
. . . . . . . . count = count + 1
if is_odd(count) then
. . . . . . . . return inside
. . . . else
. . . . . . . . return outside

See Ray-casting algorithm

Kilinich calculates the mouse position relative to the non-rotated polygon. He then subtracts the new mouse position from each line segment end point. If the new endpoints are above and below zero, and the new line segment is to the right of zero, then add one to the count. If the final count is odd then inside polygon.

Q: Where does the ray start?
A: The ray starts from zero (which is the mouse position after translation).

P.S. I just noticed I did a similar scene 4 years ago with Mouseover Code Injector. My approach at the time was to divide the polygon into triangles made from the polygon center and line segment end points and then check to see if the mouse position was inside any triangle.
Last edited at 2023/06/18 13:42:39 by s_noonan
Now the circle can be chopped up and each piece detects the cursor.

Here's a caveat: If you chop up those geometries into many smaller pieces, the computer lag will increase in proportion to how many peaces you make. So, don't over-do it!