Given two points pointU and pointV in XY-space, we need to find a point which has integer coordinates and lies on a line going through points pointU and pointV.
If pointU = (1, -1 and pointV = (-4, 1) then equation of line which goes through these two points is, 2X + 5Y = -3 One point with integer co-ordinate which satisfies above equation is (6, -3)
We can see that once we found the equation of line, this problem can be treated as Extended Euclid algorithm problem, where we know A, B, C in AX + BY = C and we want to find out the value of X and Y from the equation.
In above Extended Euclid equation, C is gcd of A and B, so after finding out the line equation from given two points if C is not a multiple of gcd(A, B) then we can conclude that there is no possible integer coordinate on the specified line. If C is a multiple of g, then we can scale up the founded X and Y coefficients to satisfy the actual equation, which will be our final answer.
Integer Point : 6 -3
This article is contributed by Utkarsh Trivedi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
- Direction of a Point from a Line Segment
- Find middle point segment from given segment lengths
- Find the other end point of a line with given one end and mid
- Program to find the mid-point of a line
- Find foot of perpendicular from a point in 2 D plane to a Line
- Reflection of a point about a line in C++
- Perpendicular distance between a point and a Line in 2 D
- Check whether the point (x, y) lies on a given line
- Shortest distance between a Line and a Point in a 3-D plane
- Section formula (Point that divides a line in given ratio)
- Program to find area of a Circular Segment
- Program to find slope of a line
- Find points at a given distance on a line of given slope
- Program to find line passing through 2 Points
- Find the Missing Point of Parallelogram