Answer the question
In order to leave comments, you need to log in
How to find all integer points of a segment?
Known segment given by two points (x1, y1), (x2, y2).
I need to find all integer points lying on this segment.
How to find all these points?
Answer the question
In order to leave comments, you need to log in
For arbitrary (x₁, y₁) and (x₂, y₂), IMHO, just take all integer values between x₁ and x₂ and check the value of y at the resulting points.
For integers (x₁, y₁) and (x₂, y₂) you can do this:
n = gcd(|x₂ − x₁|, |y₂ − y₁|)
dx = (x₂ − x₁) / n
dy = (y₂ − y₁) / n
And take all pairs (x₁ + dx × i, y₁ + dy × i) for i = 1 .. n − 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question