Given plane points p,q,r how do you decide whether the triangle contains an integral point? I want to list all such points.
It has a subproblem: Given a fourth point s. How do you decide whether s is inside the triangle?
Given plane points p,q,r how do you decide whether the triangle contains an integral point? I want to list all such points.
It has a subproblem: Given a fourth point s. How do you decide whether s is inside the triangle?
You need triangle rasterization.
Possible approach: sort vertices by Y-coordinate, for every vertical interval between vertices determine side equations and for every integer Y in this interval get left and right integer points, then fill whole horizontal scanline of inner points.
For example, "left top" side of triangle has equation 2.2*y - x + 1.5 = 0
in y-range 3.14..17.3
. The first integer Y is 4, substitution gives 10.3 - x = 0
, so the leftmost integer x value is 11. Similar procedure for right edge gives the rightmost value (say p), so we output points (11,4), (12,4)...(p,4)
subproblem
- this is completely different problem. It is not needed for retrieving all integral points.
If you really need it - calculate signs of cross products of sides with vector to point (AB x AP, BC x BP, CA x CP
)