|Perl: the Markov chain saw|
Points, Lines. Polygons OO myby mitd (Curate)
|on Aug 31, 2001 at 12:25 UTC||Need Help??|
mitd has asked for the wisdom of the Perl Monks concerning the following question:
Recently vroom dropped into CB looking for a some code that would answer the question that given a polygon and a point does point live inside the polygon. I am sure Tim has found or built his solution by now but it got to thinking since I was in a an ojective kind of mood I might take a crack for my own amusement.
First I dug up an algorithm1 and came up with some classes.
Next we need, as per algorithm three methods/functions:
Now where to stick methods?? Well inside could certainly live inside Polygon but both same_line and intersect deal with Lines(plural). So create a Lines class ?? Maybe just christian them all Helpers and stick 'em in a GeometryHelper class.
I have a sneaking suspicion there is a twisted Perly path to this design and that is why I am seeking a sober second opinion from the Monk collective.
1 ... given a polygon represented as an array of points and another point, determine whether the point is inside or outside. Draw a line segment form the point long enough thats its endpoint is guaranteed to be outside the polygon and count the number of lines from the polygon it crosses. If LX mod 2 != 0 then point is inside polygon.
Algorithms, Sedgewick, Addison-Wesley, 1983
mitd-Made in the Dark