Which Program is Best for Plotting 3D Trajectories?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 5K views
Adoniram
Messages
93
Reaction score
6
Howdy folks,

I have been given the opportunity to do some extra credit for my mechanics class. As an assignment, my prof would like to see a 3D trajectory plotted via a program (like Python).

My basic assignment is to plot the trajectory of a soccer ball after it has been kicked. I don't need help with the physics equations, but I need to know what programs I can use and if one is better than the other. No worries learning the coding language, I have a lot of experience with Java, vb script, etc...

Ideally, I'd like to use a program that has a simple 3D plot of trajectory, and it would be even better if I could save the results as an independent program. If not, no big deal. Also, it would be superb if I could put in switches in the graphical output for things like turning wind on and off, air resistance, etc... If not, I'm sure I can just write multiple programs for each instance.

Thanks!
 
Physics news on Phys.org
I would use Maple (since that's the one I have experience with) or something equivalent to it.
 
MATLAB is generally the standard in the dynamics community. FreeMat and Octave are open source clones of MATLAB.

There is a plot3 command in MATLAB that will do what you want.

Here's an example MATLAB simulation of a mass attached to a spring that behaves as a pendulum; its equations of motion are:
[tex] \begin{align*}<br /> \ddot{r} &= r\dot{\theta}^2 - \frac{k}{m}(r-l) \\<br /> \ddot{\theta} &= -\frac{2\dot{r}\dot{\theta}}{r}<br /> \end{align*}[/tex]
Code:
[i]%% Example simulation of a dynamical system.[/i][/color]
r0 = 1;
l = 1;
rdot0 = rand[/color](1,1);
theta0 = rand[/color](1,1);
thetadot0 = rand[/color](1,1);
x0 = [r0 theta0 rdot0 thetadot0]'[/color];

[t x] = ode45(@pendulum, [0 100], x0);

r = x(:, 1);
theta = x(:, 2);

x = r .*[/color] sin[/color](theta);
y = r .*[/color] cos[/color](theta);

plot(x, y, x(1), y(1), '+g'[/color], x([b]end[/b][/color]), y([b]end[/b][/color]), 'xr'[/color], 'MarkerFaceColor'[/color], 'r'[/color], 'linewidth'[/color], 3);
    tl = title('X-Y Position of Spring-Mass Pendulum'[/color]);
    xl = xlabel('x'[/color]);
    yl = ylabel('y'[/color]);
    set([tl xl yl], 'fontsize'[/color], 16);
    legend('Path'[/color], 'Start'[/color], 'End'[/color], 'Location'[/color], 'NorthEastOutside'[/color]);

Code:
[b]function[/b][/color] [/color] xdot = [/color] pendulum[/color](t, x)
    [/color]m = 1;
    k = 1;
    l = 1;

    r = x(1); theta = x(2); v = x(3); w = x(4);
    xdot = [v;
            w;
            r .*[/color] w.^[/color]2 -[/color] k/[/color]m *[/color] (r -[/color] l);
            -[/color]2 *[/color] v *[/color] w /[/color] r;
    ];
[b]end[/b][/color]

What you want to do will be much simpler than this, but this example should give you a taste of MATLAB.
 
Last edited: