# Efficient way to get integral points of segment from two points in grid

I have two lattice (grid) end points of the line, how can I generate intermediate points of the line segment between them?
One way is iterate through all the x points or y points and check (solve line equation) if the coordinates we get each time are integral solution or not.

• I suggest rephrasing the question to include all necessary details, as well as to clearly indicate what the desired output is like. Please spend a few minutes making your question as clear as possible, using as many words as necessary. Feb 9, 2018 at 15:37

For a line segment defined by two integral lattice points $(x_0,y_0), (x_1,y_1)$ there will be $gcd(y_1-y_0,x_1-x_0)-1$ additional integral points along the line segment. To find them move along line by largest value in the reduced slope.