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.
Input : r = 5. Output : 12 Below are lattice points on a circle with radius 5 and origin as (0, 0). (0,5), (0,-5), (5,0), (-5,0), (3,4), (-3,4), (-3,-4), (3,-4), (4,3), (-4,3), (-4,-3), (4,-3). are 12 lattice point.
To find lattice points, we basically need to find values of (x, y) which satisfy the equation x2 + y2 = r2.
For any value of (x, y) that satisfies the above equation we actually have total 4 different combination which that satisfy the equation. For example if r = 5 and (3, 4) is a pair which satisfies the equation, there are actually 4 combinations (3, 4) , (-3,4) , (-3,-4) , (3,-4). There is an exception though, in case of (0, r) or (r, 0) there are actually 2 points as there is no negative 0.
// Initialize result as 4 for (r, 0), (-r. 0), // (0, r) and (0, -r) result = 4 Loop for x = 1 to r-1 and do following for every x. If r*r - x*x is a perfect square, then add 4 tor result.
Below is the implementation of above idea.
This article is contributed by Shivam Pradhan (anuj_charm). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Equation of circle when three points on the circle are given
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Area of the circle that has a square and a circle inscribed in it
- Number of Integral Points between Two Points
- Minimum number of points to be removed to get remaining points on one side of axis
- Ways to choose three points with distance between the most distant points <= L
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Non-crossing lines to connect points in a circle
- Queries on count of points lie inside a circle
- Angular Sweep (Maximum points that can be enclosed in a circle of given radius)
- Check whether it is possible to join two points given on circle such that distance between them is k
- Number of quadrilateral formed with N distinct points on circumference of Circle
- Find N random points within a Circle
- Check if a circle lies inside another circle or not
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Find the radii of the circles which are lined in a row, and distance between the centers of first and last circle is given
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
Improved By : nitin mittal