i_love_downvotes's blog

By i_love_downvotes, history, 4 years ago, In English

https://cp-algorithms.com/geometry/point-in-convex-polygon.html

In above link, the code for checking whether a point is inside a convex polygon is flawed. I tested on some examples, it gave wrong answer.

Can someone point out the mistake and thus request the author to correct it!

  • Vote: I like it
  • +15
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +12 Vote: I do not like it

This blog was actually helpful.

I'm sorry but I upvoted you

»
4 years ago, # |
  Vote: I like it +10 Vote: I do not like it

Could you provide the test you were testing with?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    One of the tests is:

    Polygon points: (1,1) (6,2) (2,5)

    Query point: (0,0)

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it +3 Vote: I do not like it

      In the function prepare, the code moves the polygon by -points[0], and in the code pointInConvexPolygon, it doesn't move the point being queries. So I think if you wanna check the point (0, 0), you're supposed to query (0, 0)-(1, 1)=(-1, -1). And querying (-1, -1) does return 0. I think it's just a bad documentation / weird formating of the function on their part.