1
$\begingroup$

I'm numerically solving some differential equations and the 3D curve I get has a very complicated shape and size that cannot be predicted from the initial conditions.

I need to rescale the whole curve to fit it entirely inside the cube defined below. As a simple example, lets say the curve is this one (the real curve is much more complicated than that, and strongly depends on the initial conditions !) :

curve = ParametricPlot3D[
    {0.2 t (Sin[3 t] - 2), 0.2 t (Cos[5 t] + 1), t},
    {t, 0, 2Pi},
    Boxed -> True,
    PlotRange -> All,
    Axes -> True,
    AxesOrigin -> {0, 0, 0}
]

Now, I would like to rescale the whole curve so it fits entirely inside a centered cube of size 10 :

cube = Graphics3D[{Opacity[0.2], Cuboid[{-5, -5, -5}, {5, 5, 5}]}];

Show[{curve, cube},
    Axes -> True,
    AxesOrigin -> {0, 0, 0},
    Method -> {"RotationControl" -> "Globe"},
    ImageSize -> {700, 700}
]

Take note that the curve is starting at the origin : {0, 0, 0}, and should still be starting at that same point after rescaling.

How can I do that rescaling ?

Just in case this is important : the real curve would be shown with a Manipulate code, to change the initial conditions. When I change these, the curve's shape and size change accordingly, but it still need to be rescaled to fit inside the same cube.

$\endgroup$
2
$\begingroup$

Try this:

  tab = Transpose[
   Table[{0.2 t (Sin[3 t] - 2), 0.2 t (Cos[5 t] + 1), t}, {t, 0, 2 Pi,
      0.001}]];
maxX = Max[{Abs[Min[tab[[1]]]], Abs[Max[tab[[1]]]]}];
maxY = Max[{Abs[Min[tab[[2]]]], Abs[Max[tab[[2]]]]}];
maxZ = Max[{Abs[Min[tab[[3]]]], Abs[Max[tab[[3]]]]}];
sc = 5*{1/maxX, 1/maxY, 1/maxZ};
Show[{Graphics3D[{Opacity[0.2], Cuboid[{-5, -5, -5}, {5, 5, 5}]}],

  ParametricPlot3D[{0.2 t (Sin[3 t] - 2), 0.2 t (Cos[5 t] + 1), t}*
    sc, {t, 0, 2 Pi}, Boxed -> True, PlotRange -> All, Axes -> True, 
   AxesOrigin -> {0, 0, 0}]
  }]

enter image description here

Have fun!

$\endgroup$
  • $\begingroup$ It's working. I'll study this answer. Thanks a lot ! $\endgroup$ – Cham Mar 26 '16 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.