0
$\begingroup$

Starting from what is read here, write the following code:

spring[r_, x1_, x2_] := Module[{m, n},
    xvalues = Table[m, {m, x1, x2, (x2 - x1)/1000}];
    yvalues = Table[r Sin[n Pi/2], {n, 0, 100, .1}];
    zvalues = Table[r Cos[n Pi/2], {n, 0, 100, .1}];
    Line[Transpose@{xvalues, yvalues, zvalues}]] /. Line -> Tube;

x[t_] := 10 Cos[t]
tmax = 15;
xmin = NMinValue[{x[t], 0 <= t <= tmax}, t];
xmax = NMaxValue[{x[t], 0 <= t <= tmax}, t];

Magnify[
 Graphics3D[
  {
   spring[.2, xmin - .1, x[0]],
   {LightGray, Sphere[{x[0], 0, 0}, .3]}
  },
  Axes -> {True, False, False},
  Boxed -> False,
  ImageSize -> {200, 200},
  Lighting -> "Neutral",
  PlotRange -> {{xmin - .1, xmax + .1}, {-1, 1}, {-1, 1}},
  PlotRangePadding -> 1,
  ViewPoint -> Above],
1.5]

you get:

enter image description here

Unfortunately, if I choose x[t_] := Cos[t] the result would be the following:

enter image description here

So the question is as follows: how can I do so to make the size of the graphic representation always equal and only change the x-axis scale?

Thank you!

$\endgroup$
4
  • $\begingroup$ Inside frames you have to specify a fixed ImageSize. In addition to that (also inside frames) you should set ViewVertical (to control magnification) and PlotRangePadding. $\endgroup$
    – eldo
    Aug 19 '17 at 13:06
  • $\begingroup$ I have tried and are almost there. I just want the x-axis to be always equal like ImageSize, changing only the scale in it. It's possible? Thank you! $\endgroup$
    – TeM
    Aug 19 '17 at 15:18
  • $\begingroup$ Try AspectRatio->1/4 (inside frames) $\endgroup$
    – eldo
    Aug 19 '17 at 19:08
  • $\begingroup$ Unfortunately, by doing this the ball becomes oval and so on. I have tried to simplify the request so that we can concentrate on the essentials. $\endgroup$
    – TeM
    Aug 20 '17 at 8:54

Your Answer

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

Browse other questions tagged or ask your own question.