Circle and Lattice Points - GeeksforGeeks
Given a circle of radius r in 2-D with origin or (0, 0) as center. The task is to find the total lattice points on circumference. Lattice Points are points with coordinates as integers in 2-D space.
To find lattice points, we basically need to find values of (x, y) which satisfy the equation x2 + y2 = r2.
Read full article from Circle and Lattice Points - GeeksforGeeks
Given a circle of radius r in 2-D with origin or (0, 0) as center. The task is to find the total lattice points on circumference. Lattice Points are points with coordinates as integers in 2-D space.
To find lattice points, we basically need to find values of (x, y) which satisfy the equation x2 + y2 = r2.
int countLattice(int r){ if (r <= 0) return 0; // Initialize result as 4 for (r, 0), (-r. 0), // (0, r) and (0, -r) int result = 4; // Check every value that can be potential x for (int x=1; x<r; x++) { // Find a potential y int ySquare = r*r - x*x; int y = sqrt(ySquare); // checking whether square root is an integer // or not. Count increments by 4 for four // different quadrant values if (y*y == ySquare) result += 4; } return result;}