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.
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.
pp 312-317
Algorithms, Sedgewick, Addison-Wesley, 1983
First I dug up an algorithm1 and came up with some classes.
|
|
|
Next we need, as per algorithm three methods/functions:
- inside
- intersect -- used by inside
- same_line -- used by intersect
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.
Note
- This is not a solicitation for code.
- If you suspect this is homework you are correct. In my spare time (thats the time I have after; 'tending to the needs of my wife and 7 kids, sheperding a small pod of programmers and trying to keep my customers happy) I am doing a double PHD in Philosphy (Thesis: What is the Point) and Physics (Thesis: Where is the Point)
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.
pp 312-317
Algorithms, Sedgewick, Addison-Wesley, 1983
mitd-Made in the Dark
'My favourite colour appears to be grey.'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Points, Lines. Polygons OO my
by mirod (Canon) on Aug 31, 2001 at 13:50 UTC | |
Re: Points, Lines. Polygons OO my
by Zaxo (Archbishop) on Aug 31, 2001 at 13:08 UTC | |
Re: Points, Lines. Polygons OO my
by blakem (Monsignor) on Aug 31, 2001 at 12:53 UTC | |
Re: Points, Lines. Polygons OO my
by jbert (Priest) on Aug 31, 2001 at 16:41 UTC | |
What fun...
by Rhose (Priest) on Aug 31, 2001 at 22:19 UTC | |
Re: Points, Lines. Polygons OO my
by kapper (Chaplain) on Aug 31, 2001 at 20:30 UTC | |
Re: Points, Lines. Polygons OO my
by SilverB1rd (Scribe) on Aug 31, 2001 at 19:00 UTC | |
Re: Points, Lines. Polygons OO my
by MZSanford (Curate) on Sep 07, 2001 at 13:11 UTC |
Back to
Seekers of Perl Wisdom