3

I need to plot a figure combining of a three-dimensional ellipsoid and its projections on the sides of a box. I have no idea about it. I need to have something like

enter image description here

in Mathematica. Thanks.

corey979
  • 23,947
  • 7
  • 58
  • 101
AYBRXQD
  • 1,085
  • 6
  • 16

2 Answers2

8
pp3d = ParametricPlot3D[{2 Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]}, 
  {v, 0, π}, {u, 0, 2 π},
  BoundaryStyle -> Directive[Thick, Blue], 
  MeshFunctions -> {# &, #2 &, #3 &}, Mesh -> {{0}, {0}, {0}}, 
  MeshStyle -> (Directive[Thick, #] & /@ {Red, Blue, Green}), 
  PlotStyle -> Opacity[.3], 
  PlotRange -> {{-4, 4}, {-3, 3}, {-3, 3}}, Axes -> True, 
  AxesOrigin -> {0, 0, 0}, Ticks -> False]

enter image description here

Post-process to project the lines to three walls:

Normal[pp3d] /. Line[x_, ___] :> 
{Line[x], Line /@ (x /. 
     {{{a_, b_, c_} :> {-4, b, c}},
      {{a_, b_, c_} :> {a, 3, c}}, 
      {{a_, b_, c_} :> {a, b, -3}}})}

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
5

First, you needs in coordinates of ellipsoid surface points:

a = 1; b = 0.5; c = 0.5;
cp = ContourPlot3D[
  x^2/a^2 + y^2/b^2 + z^2/c^2 == 1, 
  {x, -1.1, 1.1}, {y, -1.1, 1.1}, {z, -1.1, 1.1}][[1,1]];

Further, just make the projections:

cp2d = cp[[All, {1, 2}]];
cm = SortBy[MeshCoordinates[ConvexHullMesh[cp2d]], 
   ArcTan[#[[1]], #[[2]]] &];
cm3dz = Insert[#, 1.1, 3] & /@ cm;
cp2d = cp[[All, {1, 3}]];
cm = SortBy[MeshCoordinates[ConvexHullMesh[cp2d]], 
   ArcTan[#[[1]], #[[2]]] &];
cm3dy = Insert[#, 1.1, 2] & /@ cm;
cp2d = cp[[All, {2, 3}]];
cm = SortBy[MeshCoordinates[ConvexHullMesh[cp2d]], 
   ArcTan[#[[1]], #[[2]]] &];
cm3dx = Insert[#, 1.1, 1] & /@ cm;

Draw the solutions:

Show[cp, 
Graphics3D[{EdgeForm[{Black, Thick}], Transparent, 
Polygon@cm3d, Polygon@cm3dx, Polygon@cm3dy}]]

enter image description here

Rom38
  • 5,129
  • 13
  • 28