Given a circle of radius r and center in point(x1, y1) and given a point(x2, y2). The task is move center of circle from given center (x1, y1) to target (x2, y2) using minimum number of steps. In one step, we can put a pin on the border of the circle at any point, then rotate the circle around that pin by any angle and finally remove the pin.
Input : r = 2 x1 = 0, y1 = 0 x2 = 0, y2 = 4 Output :1 Input : r = 1 x1 = 1, y1 = 1, x2 = 4, y2 = 4 Output : 3
Let’s consider a straight line between the two centers. Clearly to move the center with maximum distance we need to rotate it around the line and with 180 degrees. So the maximum distance we can move the center each time is 2 * r. Let’s continue moving the center with 2 * r distance each time until the two circles intersects. Now obviously we can make the center moves into its final position by rotating it around one of the intersection points of the two circles until it reaches the final destination.
Every time we make the circle moves 2 * r times except the last move it’ll be < 2 * r. Let the initial distance between the two points be d. Solution to the problem will be ceil(d/2*r).
Time Complexity : O(1)
This article is contributed by Rakesh 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.
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Distance of chord from center when distance between center and another equal length chord is given
- Find the center of the circle using endpoints of diameter
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Equation of circle when three points on the circle are given
- Check if a circle lies inside another circle or not
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Area of the circle that has a square and a circle inscribed in it
- Check whether two convex regular polygon have same center or not
- Number of cycles formed by joining vertices of n sided polygon at the center
- Puzzle | Connect 9 circles each arranged at center of a Matrix using 3 straight lines
- Find minimum radius such that atleast k point lie inside the circle
- Minimum cuts required to divide the Circle into equal parts
- Minimum Enclosing Circle | Set 1
- Minimum enclosing circle | Set 2 - Welzl's algorithm
- Check if it is possible to move from (a, 0) to (b, 0) with given jumps
- Check if it is possible to move from (0, 0) to (x, y) in N steps
- Non-crossing lines to connect points in a circle
- Circle and Lattice Points