Lattice points on a line segment between two points \((x_1, y_1)\) and \((x_2, y_2)\) are integer-coordinate points on the segment. The number of such points (including endpoints) is given by:

["Understanding Lattice Points on a Line Segment: Counting Integer-Coordinate Points Between Two Points", "Linear geometry and number theory meet in an elegant and practical concept: determining how many lattice points — points with integer coordinates — lie on a finite line segment between two given points ((x_1, y_1)) and ((x_2, y_2)). This question arises not only in pure mathematics but also in computer graphics, geographic mapping, and algorithm design.", "A question central to this topic is: How many integer-coordinate points (lattice points) lie on the straight line segment connecting ((x_1, y_1)) and ((x_2, y_2)), including the endpoints?", "The formula governing this count hinges on the greatest common divisor (GCD) of the differences in coordinates, revealing a beautiful interplay between geometry and number theory.", "---", "### The Mathematical Formula", "Let ((x_1, y_1)) and ((x_2, y_2)) be two points in the plane with integer coordinates. The number (L) of lattice points on the line segment from ((x_1, y_1)) to ((x_2, y_2)), including endpoints, is given by:", "[\nL = \ ext{gcd}(|x_2 - x_1|, |y_2 - y_1|) + 1\n]", "Here, (\ ext{gcd}(a, b)) denotes the greatest common divisor of integers (a) and (b), and the absolute differences ensure correctness regardless of coordinate order.", "If the segment passes only through its endpoints, this formula counts exactly the number of integer points along the straight path.", "---", "### Why Does This Formula Work?", "Imagine drawing the line segment on a coordinate grid. The segment spans a horizontal distance of (|x_2 - x_1|) and vertical distance of (|y_2 - y_1|). The key insight lies in the slope: (\frac{\Delta y}{\Delta x}). For the path to contain intermediate lattice points, the fraction (\frac{\Delta y}{\Delta x}) must simplify to a rational number.", "The line crosses vertical and horizontal lines between integer coordinates at regular intervals. The total number of such crossings depends on how many times the fraction (\frac{\Delta y}{\Delta x}) aligns with the smallest unit — dictated by their GCD.", "Specifically, suppose the simplified slope in lowest terms is (\frac{p}{q}), where (p) and (q) are coprime integers. Then the line advances (p) units vertically for every (q) units horizontally (or vice versa, depending on sign and orientation). This periodicity limits lattice points to spacing defined by:", "[\n\gcd(|x_2 - x_1|, |y_2 - y_1|)\n]", "Each step corresponds to a fundamental "unit segment" containing exactly one lattice point. Adding one accounts for the starting point.", "---", "### Examples to Clarify", "Example 1:\nPoints: ((0, 0)) and ((6, 4))\n[\n\Delta x = 6, \quad \Delta y = 4 \quad \Rightarrow \quad \gcd(6, 4) = 2\n]\nNumber of lattice points:\n[\nL = 2 + 1 = 3\n]\nIndeed: ((0,0), (3,2), (6,4))", "Example 2:\nPoints: ((1, 2)) and ((4, 5))\n[\n\Delta x = 3, \quad \Delta y = 3 \quad \Rightarrow \gcd(3,3) = 3\n]\nNumber of lattice points:\n[\nL = 3 + 1 = 4\n]\nThese are: ((1,2), (2,3), (3,4), (4,5))", "---", "### Handling Coordinate Directions", "Because absolute values are used in the formula, the direction of the line does not affect the count. Whether the segment rises, falls, or is horizontal, the lattice point count depends only on the relative spacing between coordinates — governed by the GCD of differences.", "---", "### Practical Implications and Applications", "- Computer Graphics & Pathfinding: Efficiently detecting grid points on lines speeds up collision detection and rendering.\n- Number Theory: Illustrates how algebraic structures (gcd) describe geometric properties.\n- Geography & Mapping: Useful in GIS for operations on linear features like roads and boundaries.", "---", "### Summary", "Counting lattice points between two integer-coordinate points simplifies to computing the GCD of the coordinate differences and adding one. The formula:", "[\nL = \gcd(|x_2 - x_1|, |y_2 - y_1|) + 1\n]", "elegantly captures the discrete nature of the segment — revealing exactly how many integer-coordinate points lie along any straight-line path in the Cartesian plane.", "Understanding this concept deepens insight into the harmony between geometry and number theory, with broad applications across science and technology.", "---", "References:\n- Graham, R., Synthesis of Combinatorial Geometry\n- Knuth, D. E., The Art of Computer Programming, Volume 1\n- Online geometry and number theory resources (e.g., MathWorld, OEIS)"]









