Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:

  • 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.


  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.'

In reply to Points, Lines. Polygons OO my by mitd

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2023-02-06 10:02 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (33 votes). Check out past polls.