http://qs1969.pair.com?node_id=109325

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.

Point
X
Y
Line
Point1
Point2
Polygon
SortedPoints[1..n]

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.

Note

  1. This is not a solicitation for code.
  2. 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.'