Skip to main content
Tweeted twitter.com/StackMma/status/1359925185571414016
edited tags
Link
Became Hot Network Question
Source Link

Determine and plot major and minor axes of ellipse

I have an element (El) constructed from a list of nodal coordinates (Nodes).

Note: The list of nodes can be arbitrarily long.

I then create a minimal area ellipse that encloses all of the node using a BoundingRegion and determine the lengths of the major and minor radii of the ellipse. See example below.

enter image description here

I would like to extend this to include the calculation of the angles of the major and minor axes relative to the horizontal axis, as well as to plot these axes, preferably as dashed lines.

My code thus far is shown below.

(* Compute *)
Nodes = {{0, 0}, {48, 44}, {48, 60}, {0, 44}};
El = Polygon[Nodes];
ellipsoidBR = BoundingRegion[Nodes, "FastEllipsoid"];
ellipsoidB = RegionBoundary[ellipsoidBR];
area = RegionMeasure[ellipsoidBR];
Xc = RegionCentroid[ellipsoidBR];
a = RegionDistance[RegionBoundary[ellipsoidBR], Xc];
b = area/(Pi a );
(* Plot *)
Theta1 = 190;
Theta2 = 65;
Show[Graphics[{Opacity[0.20], ellipsoidBR}], 
 Graphics[{EdgeForm[Thick], Opacity[0.25], El}], 
 Graphics[{Thick, Circle[Xc, a]}], Graphics[{Thick, Circle[Xc, b]}], 
 Graphics[{PointSize[Large], Point[Xc]}], 
 Graphics[{PointSize[Large], Point[Nodes]}], 
 Graphics[{Thick, 
   Arrow[{Xc, {Xc[[1]] + a Cos[Theta1 Degree], 
      Xc[[2]] + a Sin[Theta1 Degree]}}]}], 
 Graphics[{Thick, 
   Arrow[{Xc, {Xc[[1]] + b Cos[Theta2 Degree], 
      Xc[[2]] + b Sin[Theta2 Degree]}}]}]]

Any help would be appreciated!