Given the co-ordinates of a 2-dimensional point p(x0, y0). Find the points at a distance L away from it, such that the line formed by joining these points has a slope of M.
Input : p = (2, 1) L = sqrt(2) M = 1 Output :3, 2 1, 0 Explanation: The two points are sqrt(2) distance away from the source and have the required slope m = 1. Input : p = (1, 0) L = 5 M = 0 Output : 6, 0 -4, 0
We need to find two points that are L distance from given point, on a line with slope M.
The idea has been introduced in below post.
Find Corners of Rectangle using mid points
Based on the input slope, the problem can be classified into 3 categories.
- If slope is zero, we just need to adjust the x coordinate of the source point
- If slope is infinite, the we need to adjust the y coordinate
- For other values of slope, we can use the following equations to find the points
Now using the above formula we can find the required points.
3, 2 1, 0 6, 0 -4, 0
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.