Point in or out

This is a discussion on Point in or out within the C Programming forums, part of the General Programming Boards category; Hello. Given a polygon (could be regular, irregular, convex, concave), find out whether a particular point lies inside it or ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    16

    Point in or out

    Hello.

    Given a polygon (could be regular, irregular, convex, concave), find out whether a particular point lies inside it or outside it.

    This question was asked within an interview. what should be the approach to get this information.

    Thanks.
    Stuart.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    For a 2D polygon, if you raytrace (draw) a line across it, depending on how many edges of the polygon your cross, the point is inside or outside the polygon.

    Another way might be its bounding box, depending on how the bounding boxes are defined for that object.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    As Salem pointed out, generally figuring out the correct place where to ask questions is a far more important thing for you to work on that finding an algorithm that solves the given problem.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help realy needed
    By ZohebN in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2008, 10:37 AM
  2. Getting a floating point exception
    By SnertyStan in forum C Programming
    Replies: 13
    Last Post: 03-25-2008, 12:00 PM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 03:39 PM
  4. floating point binary program, need help
    By ph34r me in forum C Programming
    Replies: 4
    Last Post: 11-10-2004, 07:10 AM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 04:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21