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
This article is contributed by Ashutosh Kumar 😀 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.
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.
- Slope of the line parallel to the line with the given slope
- Program to find slope of a line
- Slope of perpendicular to line
- Ways to choose three points with distance between the most distant points <= L
- Find the slope of the given number
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Find X and Y intercepts of a line passing through the given points
- Find the maximum possible distance from origin using given points
- Find integral points with minimum distance from given set of integers using BFS
- Program to find line passing through 2 Points
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Haversine formula to find distance between two points on a sphere
- Find the integer points (x, y) with Manhattan distance atleast N
- Represent a given set of points by the best possible straight line
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
- Check whether it is possible to join two points given on circle such that distance between them is k
- Distance between end points of Hour and minute hand at given time
- Number of Integral Points between Two Points
- Prime points (Points that split a number into two primes)
- Minimum number of points to be removed to get remaining points on one side of axis
Improved By : Rajnis09