IsPointInsidePolygon

bk shared this question 14 years ago
Answered

Is there a predefined function to check whether a point is inside the (possibly nonconvex) polygon? If there isn't, how can I define it?

Comments (5)

photo
1

ideas:


1º) define isinsidetriangle[A,B,C,H] (could be using baricentre coords and solving the system or another processing)


2º) H is inside poly[A,B,C,D,E,F,G] when the number isinsidetriangle[A,B,C,H]+isinsidetriangle[A,C,D,H]+isinsidetriangle[A,D,E,H]+isinsidetriangle[A,E,F,H] + isinsidetriangle[A,F,G,H] is a odd number


i hope to be useful


saludos

photo
1

new idea:


IsInsideTriangle[A,B,C,H]=polygon[A,B,C]==polygon[A,B,H]+polygon[B,C,H]+polygon[A,C,H]


saludos

photo
1

I don't know barycentric coords, so I don't really have an idea how to do this.


But I did try to implement a PointInsideTriangle using the winding number method: the sum of angles ADB, BDC and CDB is 0 iff D is outside triangle ABC. This worked to some extent: if you changed the triangle orientation by moving one of the vertex points, the result came out wrong.

photo
1

don't use baricentric coords


use the idea my last reply for point inside triangle

photo
1

new idea:

IsInsideTriangle[A,B,C,H]=polygon[A,B,C]==polygon[A,B,H]+polygon[B,C,H]+polygon[A,C,H]


You're right, this works. In fact, I even tried something like this in my very first try but I must have mistyped something because I got wrong result in some cases.


However, it's not possible to define this as a function in a single line as above, is it? I do "t=If[poly1==poly2+poly3+poly4,1,0]" and then construct a macro...

© 2021 International GeoGebra Institute