Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Points, Lines. Polygons OO my

by blakem (Monsignor)
on Aug 31, 2001 at 12:53 UTC ( #109329=note: print w/replies, xml ) Need Help??

in reply to Points, Lines. Polygons OO my

I don't quite get it.. If this isn't a code solicitation, are you looking for a discussion of how the objects might behave, or at clever ways of attacking the problem...

My first thought would be to:

Given Point A(x,y) and Polygon P with vertices V1..Vn
1.) Create Point B(x,y) such that Bx is greater than all x values of the vertices, and By is greater than all y values of the vertices
2.) Check each edge of P (including endpoints, but excluding those with both endpoints on AB) to see if it intersects segment AB, if so $count++. (fairly trivial, left to excercise for the reader.)
3.) for (V1..Vn) {$count-- if V is on AB} as they were double counted in step 2
4.) $inside = $count%2;

I think I could probably golf that in 150 chars or less... ;-)

Or, maybe you were looking for a discussion on your objects...


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://109329]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2023-02-05 11:33 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (31 votes). Check out past polls.