Hello! I am unable to find any resource on implementing pick's theorem for a polygon in c++. Can anyone suggest me a site or code where i can understand it.
Thanks.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Name |
---|
Well Pick Theorem states that:
S = I + B / 2 - 1
WhereS
— polygon area,I
— number of points strictly inside polygon andB
— Number of points on boundary.In 99% problems where you need to use this you are given all points of a polygon so you can calculate
S
andB
easilySo by having S and B you can get
I
using some simple maths:I = S + 1 - B / 2
I did not understand how you found boundary points. Can you explain in detail.Photon_
So points with integer coordinates on line segment is GCD(dx,dy) + 1
Where GCD is Greatest common divisor, dx is distance between x coordinates of points, dy — is distance between y coordinates of points
That
-1
should not be there.EDIT: Ah sorry I missed the
= A.size()
, it works out fine, my bad.yo on weed?
what happens if vertices of polygon don't have integer coordinates? how to handle that case?
It also works for rationals, and all the numbers you can read are rational ... you can maybe multiply them by $$$\frac{1}{\epsilon}$$$. with $$$\epsilon$$$ the minimum $$$10^{-k}$$$ value that you can work.
(https://www.google.com/amp/s/www.geeksforgeeks.org/count-integral-points-inside-a-triangle/amp/)