Skip to main content
↑
↓
Spherical forums
Community for the
Sphere game engine
New?
Contact Us
to register an account!
1 Hour
1 Day
1 Week
1 Month
Forever
Community
Help
Search
Recent Posts
Log in
Contact Us
News
Spherical
Facebook
-
Twitter
-
Discord chat
New?
Contact us
to register an account!
Sphere Development
Sphere General
How PolygonCollision() came to be. (point in polygon explained with source)
1
Print
Topic: How PolygonCollision() came to be. (point in polygon explained with source)
(Read 3218 times)
previous topic
-
next topic
0 Members and 1 Guest are viewing this topic.
FBnil
Low Poster
Posts: 89
Sphere on Pandora or burst!
Logged
How PolygonCollision() came to be. (point in polygon explained with source)
June 07, 2015, 12:55:28 pm
Polygon() existed back in the old 1.5 version. But there was no easy way to detect if one polygon was touching another polygon. There also is no polygon editor. And so, nobody really used it.
Until I found a fast algorithm for
http://www.visibone.com/inpoly/
, published in 97 in the Linux Journal. In fact, the article contains several of these algorithms and puts them somewhat side by side. The code is small, fast and brilliant. And fortunately, still around. And worth the read, so check the URL out.
At that moment in time, I was more concerned with writing good interface code, than understanding the algorithm, that is why in the sources you still can see this comment:
Code:
[Select]
inside=!inside; // I nod and smile...
Yes. It is not always easy to "understand" the code. The focus and effort was more on following all JS guidelines to not leak memory (it does not leak). And getting all glue functions, documentation, testing, etc. together to add a function. At a mere 173 lines of code, it was the stepping stone for the much bigger sfxr sound generator, that was added later on.
Last Edit
: June 07, 2015, 12:58:07 pm by FBnil
Fat Cerberus
Big Chungus
Posts: 2,774
*MUNCH*
Logged
Global Moderator
Sphere Developer
Re: How PolygonCollision() came to be. (point in polygon explained with source)
Reply #1
–
June 07, 2015, 01:22:48 pm
Note that the crossing count algorithm only works reliably with simple polygons. It breaks down in the presence of self-intersection.
neoSphere 5.9.2
-
neoSphere
engine -
Cell
compiler -
SSj
debugger
forum thread
|
on GitHub
1
Print
Sphere Development
Sphere General
How PolygonCollision() came to be. (point in polygon explained with source)