Geometry
# Given two points p (x1, y1) and q (x2, y2), calculate the number of integral points lying on the line joining them.
Solution
1. If the edge formed by joining p and q is parallel to the X-axis, then the number of integral points between the vertices is : abs( y2 - y1 ) - 1 2. Similarly if edge is parallel to the Y-axis, then the number of integral points in between is : abs( x2 - x1 ) - 1 3. Else, we can find the integral points between the vertices using below formula: GCD(abs( x2 - x1 ) , abs( y2 - y1 )) - 1
Comments
Post a Comment