How many integer points within the three points forming a triangle?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Triangles are fundamental structures in geometry, and determining the number of integer points (points with integer coordinates) within a triangle is an intriguing problem. This article explores how to calculate the number of integer points within a triangle formed by three given points on a Cartesian plane.
Understanding the Problem
A triangle is defined by its vertices, which are given as coordinate pairs on a plane. The task is to determine how many points with integer-coordinate pairs lie inside (and sometimes on the boundary of) the triangle.
Given three points, , , and , we are interested in determining the integer lattice points (points where both coordinates are integers) that lie within the triangle they form.
Pick's Theorem
An essential tool for solving this problem is Pick's Theorem, which applies to simple polygons with vertices on integer points. Pick's Theorem states:
Where: • is the area of the polygon. • is the number of interior integer points. • is the number of boundary integer points.
Calculating the Area
For a triangle, the area can be calculated using the determinant method (the shoelace formula):
This formula provides the absolute value of the area of the triangle.
Calculating Boundary Points
The boundary points are those that lie on the edges of the triangle. For an edge between two points, say and , the number of integer points on this edge, excluding the endpoints, can be calculated using the greatest common divisor (GCD):
For the complete boundary count, sum up the points on all three sides and add the 3 vertices:
Calculating Interior Points
With the area and boundary points known, the number of interior integer points can be determined using Pick's theorem rearranged as:
Example Calculation
Consider a triangle with vertices , , and .
- Calculate Area:Using the shoelace formula:
- Calculate Boundary Points:• : The edge from to has 4 points. • : The edge from to has 3 points. • : The edge from to has 3 points.Total boundary points including vertices:
- Calculate Interior Points:Using Pick's theorem:
Thus, there is 1 integer point strictly within the triangle.
Summary Table
The table below summarizes how to calculate each component:
| Component | Calculation Method | Example Data |
| Area | \frac{1}{2} \left\\lvert x_1(y_2-y_3) + x_2(y_3-y_1) + x_3(y_1-y_2) \right \\rvert | 6 |
| Boundary | Sum of (for edges) | 11 |
| Interior | 1 |
The calculations effectively capitalize on geometric properties and integer arithmetic, offering a systematic way to address this classic lattice problem.
Further Considerations
- Extensions: While this article has focused on triangles, Pick's Theorem can be extended to other polygons as long as their vertices are lattice points.
- Generalization: For triangles with non-integer vertices, advanced lattice enumeration techniques become necessary.
- Computational Tools: For any scalable application, leveraging libraries in Python (e.g., SymPy or NumPy) could automate these computations on larger datasets of triangular geometries.
By understanding these basics, geometric computations involving integer lattice points become much more approachable, providing foundation for more complex geometric and topological analyses.
Related reading
- How many numbers below N are coprimes to N?
- How many palindromes can be formed by selections of characters from a string?
- How much do two rectangles overlap?
- How predict_proba in sklearn produces two columns? what are their significance?
- How to build a Language model using LSTM that assigns probability of occurence for a given sentence
- How to calculate a partial Area Under the Curve AUC
- How to calculate a standard deviation array
- How to calculate an angle from three points?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.