0
$\begingroup$

I'm new to mathematica and can't seem to make this animation work. Any help?

g = 9.81; 
x[t_] := x0 + vel*Cos[th]*t;
y[t_] := y0 + vel*Sin[th]*t - (g*t^2)/2;
vel = 0; x0 = 5; y0 = 100; th = 0;
Animate[
Graphics[
{PointSize -> 0.05, Point[{x[t], y[t]}]}] , {t, 0, 10}]

the animation is starting without error but it's just a non-moving point.

(maybe has something to do with the version of mathematica I'm using? it's v7.0 trial version)

$\endgroup$
5
  • 1
    $\begingroup$ PlotRange needs to be an option to Graphics inside Animate ( Your Graphics line does nothing at all, Graphics does not "remember" options from prior calls ) $\endgroup$
    – george2079
    Jun 19, 2017 at 14:54
  • $\begingroup$ Thanks, but that's not the issue. all it displays is a non-moving point in the midle of the screen. $\endgroup$
    – LyrcAxis
    Jun 19, 2017 at 14:59
  • $\begingroup$ It does not move because by default Graphics auto ranges every frame to center the point. Thats why you need to specify a fixed plot range. $\endgroup$
    – george2079
    Jun 19, 2017 at 15:04
  • $\begingroup$ It can also be useful to draw a box to give yourself a reference frame, try this : Graphics[{{FaceForm[None], EdgeForm[Black], Rectangle[{0, 0}, {200, 200}]}, PointSize -> 0.05, Point[{x[t], y[t]}]}] $\endgroup$
    – george2079
    Jun 19, 2017 at 15:16
  • $\begingroup$ You're a genius, thanks! it seemed to work in another version so I tried this again here. (the general graphics options) case solved $\endgroup$
    – LyrcAxis
    Jun 19, 2017 at 15:17

1 Answer 1

2
$\begingroup$
g = 9.81;
x[t_] := x0 + vel*Cos[th]*t;
y[t_] := y0 + vel*Sin[th]*t - (g*t^2)/2;
vel = 0;
x0 = 5;
y0 = 100;
th = 0;

{xmin, xmax} = #[{x[t], 0 <= t <= 10}, t] & /@
  {MinValue, MaxValue}

(*  {5, 5}  *)

{ymin, ymax} = #[{y[t], 0 <= t <= 10}, t] & /@
  {MinValue, MaxValue}

(*  {-390.5, 100.}  *)

Animate[
 Graphics[{
   PointSize -> 0.05,
   Point[{x[t], y[t]}]},
  PlotRange -> {
    {Floor[xmin - 5, 10], Ceiling[xmax + 5, 10]},
    {Floor[ymin - 5, 10], Ceiling[ymax + 5, 10]}},
  Frame -> True,
  AspectRatio -> 1], {t, 0, 10}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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