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: 468

Views: 207

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: Object Detector
Rating: 5
Filesize: 153.52 kB
Downloads: 1263
Comments: 6
Ratings: 1
Date added: 2022/09/18 02:49:58
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Object Detector
Rating: 5
Filesize: 23.32 kB
Downloads: 429
Comments: 0
Ratings: 1
Date added: 2010/12/20 13:35:17
Made with: Algodoo before v1.8.5
Rating: rated 5
download
Title: Petri dish exploration -- BACTERIA -- with CELL DETECTOR!
Rating: 5
Filesize: 86.67 kB
Downloads: 362
Comments: 0
Ratings: 1
Date added: 2016/04/23 15:06:06
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: nearest object detector
Rating: 5
Filesize: 17.79 kB
Downloads: 281
Comments: 2
Ratings: 1
Date added: 2015/02/24 22:38:21
Made with: Algodoo v2.1.0
Rating: rated 5
download
Title: Time Control
Rating: 6.1111
Filesize: 21.21 kB
Downloads: 477
Comments: 3
Ratings: 3
Date added: 2015/12/04 22:34:48
Made with: Algodoo v2.1.0
Rating: rated 6.1
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!