The smaller ellipse is contained within the larger one.
By 'minimum distance', I mean the distance that minimises;
Sqrt[(y1 - y2)^2 + (x1 - x2)^2]
By maximum, I mean the distance that maximises this, with the constraint that it must be colinear with the center of the smaller ellipse. I've given a rough drawing of these in green and purple, respectively;
For finding the minimum, I attempted using NMinimize
NMinimize[{Sqrt[(y1 - y2)^2 + (x1 - x2)^2], G[x1, y1, X1, Y1, major1, minor1] == 1 && G[x2, y2, X1, Y1, major1, minor1] == 1}, {x1, x2, y1, y2}]
but it did not like my constraints. G is the equation of an ellipse;
G[x_, y, X_, Y_, major_, minor_] = ((x - X)/major)^2 + ((y - Y)/minor)^2
where the parameters for these ellipses are;
X1 = 200; Y1 = 110; major1 = 10; minor1 = 8;
X2 = 210; Y2 = 100; major2 = 25; minor2 = 30;
I also attempted using NSolve
with a system of equations, but couldn't get that to work either.
Here's the full code I have;
X1 = 200; Y1 = 110; major1 = 10; minor1 = 8;
X2 = 210; Y2 = 100; major2 = 25; minor2 = 30;
G[x_, y, X_, Y_, major_,
minor_] = ((x - X)/major)^2 + ((y - Y)/minor)^2;
G1 = G[x, y, X1, Y1, major1, minor1];
G2 = G[x, y, X2, Y2, major2, minor2];
e1 = Plot[y /. Solve[G1 == 1], {x, 170, 250}, PlotStyle -> Blue];
e2 = Plot[y /. Solve[G2 == 1], {x, 170, 250}, PlotStyle -> Red];
Show[e1, e2, PlotRange -> Automatic, AspectRatio -> 1]
NMinimize[{Sqrt[(y1 - y2)^2 + (x1 - x2)^2],
G[x1, y1, X1, Y1, major1, minor1] == 1 &&
G[x2, y2, X1, Y1, major1, minor1] == 1}, {x1, x2, y1, y2}]
EDIT
As Syed pointed out, there was a typo in the original code (y->y_), as well as the major/minor axes being incorrectly specified in the final line. Now it works fine with NMinimize
. In case anyone is looking at this in the future, here is the updated code;
X1 = 200; Y1 = 110; major1 = 10; minor1 = 8;
X2 = 210; Y2 = 100; major2 = 25; minor2 = 30;
G[x_, y_, X_, Y_, major_,
minor_] := ((x - X)/major)^2 + ((y - Y)/minor)^2;
G1 = G[x, y, X1, Y1, major1, minor1];
G2 = G[x, y, X2, Y2, major2, minor2];
NMinimize[{Sqrt[(y1 - y2)^2 + (x1 - x2)^2], G[x1, y1, X1, Y1, major1, minor1] == 1 && G[x2, y2, X2, Y2, major2, minor2] == 1}, {x1, x2, y1, y2}]
NMaximize[{Sqrt[(y1 - y2)^2 + (x1 - x2)^2], G[x1, y1, X1, Y1, major1, minor1] == 1 && G[x2, y2, X2, Y2, major2, minor2] == 1 && (y2 - y1)/(x2 - x1) == (y2 - Y1)/(x2 - X1) && (y1 - Y1)*(y2 - Y1) >= 0 && Abs[y1 - y2] > 0.1}, {x1, x2, y1, y2}]
The Abs[y1 - y2] > 0.1
is a hacky workaround to ensure the maximum length is not passing through the inner ellipse.
G[x_, y_, X_, Y_, major_, minor_] := ((x - X)/major)^2 + ((y - Y)/minor)^2;
? $\endgroup$