Count how many points are in the polygon

Yu Wing Ha shared this question 1 month ago
Answered

Hello!

I want to count how many points are in the polygon (include vertice and any point like the image point inside the polygon.

Thank you for your help!

Comments (4)

photo
3

Place all the points to be considered in a list (Li1).

Then use the following command:


countInPoly1 = Sum(Zip(IsInRegion(P, poly1), P, Li1))

photo
1

Thank you for your help!

However, I still have some problems with the command, could you please help me again?

I have followed your guidance to create the list (Li1).

But I don't know what P refers to, please help.

countInPoly1=Sum(Zip(IsInRegion(P,poly1),P,Li1))

Thank you very much!

photo
2

P has its scope only within Zip. P is the name (freely selectable) of 1 element within Li1. With each element of Li1, P is passed to the first parameter (expression) of Zip. See also the manual.

In other words: All elements of Li1 are checked if they are inside poly1. This results in a list of boolean values which are interpreted as 1=true or 0=false with the function Sum().

photo
2

You can also use:

CountIf(IsInRegion(P,poly1),P,Li1)


Again, P is a parameter only defined within the scope of the CountIf - it does not need to be pre-existing.

photo
© 2021 International GeoGebra Institute