Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Points, Lines. Polygons OO my

by blakem (Monsignor)
on Aug 31, 2001 at 12:53 UTC ( [id://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...

-Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found