Why BoundingRegion does not work well?
Here is an answer to your first question: Using Norm[] you'll get Abs[]-terms in the functional, which are sometimes problematical. Using the sum of squares
opt = FindMinimum[{#.# &[
Apply[Function[{x,
y}, ((x - h)*Cos[\[Alpha]] - (y - k)*Sin[\[Alpha]])^2/
a^2 + ( (x - h)*Sin[\[Alpha]] + (y - k)*Cos[\[Alpha]])^2/
b^2 - 1], elip, 1]]
, -Pi <= \[Alpha] <= Pi, a > b },
{ a , b , {h, Mean[elip][[1]]}, {k, Mean[elip][[2]]} , \[Alpha] },MaxIterations -> 1000, AccuracyGoal -> 4, PrecisionGoal -> 5]
(* {0.131336, {a -> 114.631, b -> 50.1975, h -> 299.194,k -> 350.063, \[Alpha] -> 1.93331}}*)
gives this result
Show[{ContourPlot[(((x - h)*Cos[\[Alpha]] - (y - k)*Sin[\[Alpha]])^2/
a^2 + ( (x - h)*Sin[\[Alpha]] + (y - k)*Cos[\[Alpha]])^2/
b^2 - 1 /. opt[[2]]) == 0, {x, 200, 400}, {y, 200, 500}]
,Graphics[{Red,Point[elip] }]},PlotRange -> All]
for the approximation.
About your second question. It is a manifestation of an old bug in rendering of Disk
and Circle
primitives after applying GeometricTransformation
.
At first, let us see how Ellipsoid
is represented in the output:
elipse = BoundingRegion[elip, "FastEllipse"]
ToBoxes[Graphics@elipse]
Ellipsoid[{298.327, 348.756}, {{4830.73, 3097.75}, {3097.75, 12554.8}}] GraphicsBox[ InterpretationBox[ GeometricTransformationBox[ DiskBox[{0, 0}], {{{69.5034, 0.}, {44.5697, 102.802}}, {298.327, 348.756}}], Ellipsoid[{298.327, 348.756}, {{4830.73, 3097.75}, {3097.75, 12554.8}}]]]
We see that it is converted into GeometricTransformationBox
containing DiskBox
. So a minimal working example to reproduce the issue is as follows:
Graphics[{GeometricTransformation[Disk[], {{70, 0}, {44, 100}}], Red,
GeometricTransformation[Polygon[CirclePoints[100]], {{70, 0}, {44, 100}}]}]
We see that unit Disk
after transformation doesn't coincide with a Polygon
formed by points located on unit circle. If you try to resize the generated Graphics
object by dragging its corners, you will see dancing black ellipse what indicates that its rendering is extremely unstable. I reproduce this problem with Mathematica versions 8.0.4, 10.0.1 and 11.2.0, reported as [CASE:3997744].
More generally, the bug appears when we apply to a Circle
or a Disk
primitive a rotation or shearing transformation along with a scaling transform with large coefficient in any direction (100 makes the bug already visible):
Graphics[{Red, GeometricTransformation[Circle[{0, 0}, 1], 100 RotationMatrix[Pi/2]],
Black, GeometricTransformation[Circle[{0, 0}, 100], RotationMatrix[Pi/2]]},
Frame -> True]
As one can see, applying scaling coefficient to the radius of Circle
instead of the transformation matrix is a workaround for the bug. For the original issue it can be applied as follows:
Graphics[{GeometricTransformation[Disk[{0, 0}, 100], {{70, 0}, {44, 100}}/100], Red,
GeometricTransformation[Polygon[CirclePoints[100]], {{70, 0}, {44, 100}}]}]
For general workaround see this question of mine:
- How to transform general Ellipsoid into rotated axis-oriented one?
Strongly related bug:
- Plot points shifted (a lot) in output and PNG export but not in PDF export