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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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/)