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 firstname.lastname@example.org. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Find normal at a given point on the curve
- Find the Missing Point of Parallelogram
- Find Tangent at a given point on the curve
- Program to find slope of a line
- Find mirror image of a point in 2-D plane
- Find a point such that sum of the Manhattan distances is minimized
- Find a point that lies inside exactly K given squares
- Find the foot of perpendicular of a point in a 3 D plane
- Program to find GCD of floating point numbers
Improved By : ManasChhabra2