23
1
Brief Problem Explanation
Write a program to find the minimum distance between two points traveling only on rays emanating from the origin and circles centered on the origin.
Explanation of Premise
Now let's imagine we are on a plane, and on this plane we are only allowed to travel in special ways. We are allowed to travel on any ray emanating from the origin.
We can also travel on any circle centered at a circle
Now our goal is to travel from one point on this plane to another. However, we can't just travel in a simple Euclidian path, we can only do this if the points happen to fall on a ray emanating from the center.
We can travel on this one because it falls on a one of our rays.
We can also travel on circles centered at the origin.
Examples
Now here is the challenge:
We've got to get from one point to another in the shortest path; often this is a combination of traveling on circles and rays.
This, however, it could also be traveling on two rays.
Sometimes there exist two paths that travel the minimum distance.
Problem
Your challenge is to write a program that when given two points will give us the minimum distance between them if we follow these rules. The inputs can be given in either rectangular or polar forms and the output ought to be one number, the distance between.
Test Cases
(with rectangular input)
(1,1) (1,-1) -> ~ 2.22144
(0,0) (1, 1) -> ~ 1.41421
(1,0) (-0.4161 , 0.90929) -> ~ 2
(1,1) (1, 0) -> ~ 1.19961
(1,2) (3, 4) -> ~ 3.16609
Are the example test cases in rectangular or polar forms? Also: bewteen – Angs – 2016-11-20T19:28:14.070
They are in the rectangular form, I ought to clarify that – Ando Bando – 2016-11-20T19:30:13.670
Is the last example correct? I'm getting ~3.166 – Angs – 2016-11-20T20:14:17.800
The Euclidean path is the limiting case of a series of ray and circle movements, so why is the output not going to be the Euclidean distance? – Peter Taylor – 2016-11-20T21:12:06.883
6@Peter Taylor Because they are not really the same path. In a similar way a path from 0,0 to 1,1 on the xy plane via small steps alternating in the x and y directions appears identical to a direct diagonal path as the step length tends to zero. But the diagonal path has length sqrt(2) while the step path will always have length 2. – Penguino – 2016-11-20T21:26:19.873
Can the input be two complex numbers? – Luis Mendo – 2016-11-20T22:33:33.290
@LuisMendo Sure! – Ando Bando – 2016-11-20T22:48:01.677
Can we assume that the inputs will never be two of the same point, i.e.
(1,1) (1,1)
? – R. Kap – 2016-11-21T09:31:55.917In other words, can the distance between the two input points ever be zero? – R. Kap – 2016-11-21T09:50:31.013
1I think the challenge would look better if the images were not so large. Currently they make it hard to follow the text – Luis Mendo – 2016-11-21T10:06:46.430
@LuisMendo I agree, but I don't know how to do this without putting the images thru Photoshop and then replacing them, is there an easier way? – Ando Bando – 2016-11-21T14:45:00.693
@R.Kap Yeah, I think that's a fair assumption especially for golf. But it shouldn't be too hard to make it work with a distance of 0 – Ando Bando – 2016-11-21T14:46:21.637
@AndoBando I haven't tried it, but appararently yes
– Luis Mendo – 2016-11-21T14:48:12.447