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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find middle point segment from given segment lengths
- Direction of a Point from a Line Segment
- 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
- Section formula (Point that divides a line in given ratio)
- Check whether the point (x, y) lies on a given line
- Slope of the line parallel to the line with the given slope
- Rotation of a point about another point in C++
- Reflection of a point at 180 degree rotation of another point
- Reflection of a point about a line in C++
- Shortest distance between a Line and a Point in a 3-D plane
- Perpendicular distance between a point and a Line in 2 D
- Given n line segments, find if any two segments intersect
- Find points at a given distance on a line of given slope
- Program to find area of a Circular Segment
- Angle between a chord and a tangent when angle in the alternate segment is given
- How to check if two given line segments intersect?
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
- Find normal at a given point on the curve
Improved By : ManasChhabra2