Given coordinates of two pivot points (x0, y0) & (x1, y1) in coordinates plane. Along with each pivot, two different magnets are tied with the help of a string of length r1 and r2 respectively. Find the distance between both magnets when they repelling each other and when they are attracting each other.
Input : x1=0, y1=0, x2=5, y2=0, r1=2, r2=2
Output : Distance while repulsion = 9, Distance while attraction = 1
Input : x1=0, y1=0, x2=5, y2=0, r1=3, r2=3
Output : Distance while repulsion = 11, Distance while attraction = 0
As we all know about the properties of magnet that they repel each other when they are facing each other with the same pole and attract each other when they are facing each other with opposite pole. Also, the force of attraction, as well as repulsion, always work in a straight line.
We have two pivots points on coordinates, so distance between these points are D = ((x1-x2)2 +(y1-y2)2 )1/2.
Also, we can conclude that distance between magnet is maximum while repulsion and that too should be the distance between pivots + sum of the length of both strings.
In case of attraction we have two cases to take care of:
Either the minimum distance is the distance between pivots – the sum of the length of both strings
Or minimum distance should be zero in case if the sum of the length of strings is greater than the distance between pivot points.
Illustration with help of diagram:
Distance while repulsion = 17 Distance while attraction = 0
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.
- Find the maximum possible distance from origin using given points
- Find the minimum and maximum sum of N-1 elements of the array
- Find Maximum and Minimum of two numbers using Absolute function
- Program to find the minimum (or maximum) element of an array
- Puzzle | Minimum distance for Lizard
- Minimum distance to travel to cover all intervals
- Minimum distance to the corner of a grid from source
- Minimum distance from a point to the line segment using Vectors
- Maximum distance between two points in coordinate plane using Rotating Caliper's Method
- Find points at a given distance on a line of given slope
- Find the integer points (x, y) with Manhattan distance atleast N
- Haversine formula to find distance between two points on a sphere
- Find the distance covered to collect items at equal distances
- Find the radii of the circles which are lined in a row, and distance between the centers of first and last circle is given
- Find the side of the squares which are lined in a row, and distance between the centers of first and last square is given
- Count paths with distance equal to Manhattan distance
- Maximum and Minimum value of a quadratic function
- Sum of minimum and the maximum difference between two given Strings
- Find the maximum value of Y for a given X from given set of lines
- Find the Maximum possible Sum for the given conditions
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.