VON#
Confessions of a code junkie
RSS
Tuesday, August 05, 2008
Programming Job Interview Challenge Answer Week #14
Here is the question:
Programming Job Interview Challenge Question Week #14
This week was a fun and interesting question. Here is the answer
Step 1. As you're adding points to the polygon, determine a bounding rectangle by keeping track of the min x/y and the max x/y.
Step 2. Draw a line from the point you're interested in, to any point outside the bounding rectangle (because you know the outside point can't be within the polygon).
Step 3. Count the number of intersections between your newly created line and the polygon, if the number is even (0 included) the point in question is not within the polygon, if the number of intersections is odd, then the point is within the polygon.
Examples:
Outside = Even Intersections
Inside = Odd Intersections
Tuesday, August 5, 2008 - 2:33 PM CST -
Permalink
Comments [0]
-
Tags:
Comments are closed.
All Content © 2009, Jon von Gillern
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Home
Tags
Blend
Design
IADNUG
Projects
Stuff
Tips and Tricks
Wishlist
XAML
Archive
June, 2009 (1)
May, 2009 (1)
April, 2009 (2)
March, 2009 (1)
February, 2009 (2)
January, 2009 (1)
October, 2008 (1)
September, 2008 (1)
August, 2008 (1)
July, 2008 (2)
June, 2008 (2)
May, 2008 (2)
March, 2008 (2)
February, 2008 (8)
January, 2008 (4)
December, 2007 (6)
November, 2007 (2)
Blogroll
Eric Sink
Javier Lozano
Jeff Atwood
Joel Spolsky
Nick Parker
Paul Graham
Scott Hanselman
Tim Gifford