Program to plot 3D trajectory?

In summary, the program MATLAB has a plot3 command that will allow you to create a 3D trajectory of a soccer ball.
  • #1
Adoniram
94
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
  • #2
I would use Maple (since that's the one I have experience with) or something equivalent to it.
 
  • #3
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*}
\ddot{r} &= r\dot{\theta}^2 - \frac{k}{m}(r-l) \\
\ddot{\theta} &= -\frac{2\dot{r}\dot{\theta}}{r}
\end{align*}
[/tex]
Code:
[color=#408080][i]%% Example simulation of a dynamical system.[/i][/color]
r0 = 1;
l = 1;
rdot0 = [color=#008000]rand[/color](1,1);
theta0 = [color=#008000]rand[/color](1,1);
thetadot0 = [color=#008000]rand[/color](1,1);
x0 = [r0 theta0 rdot0 thetadot0][color=#666666]'[/color];

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

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

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

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

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

    r = x(1); theta = x(2); v = x(3); w = x(4);
    xdot = [v;
            w;
            r [color=#666666].*[/color] w[color=#666666].^[/color]2 [color=#666666]-[/color] k[color=#666666]/[/color]m [color=#666666]*[/color] (r [color=#666666]-[/color] l);
            [color=#666666]-[/color]2 [color=#666666]*[/color] v [color=#666666]*[/color] w [color=#666666]/[/color] r;
    ];
[color=#008000][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:

1. How can I plot a 3D trajectory in my program?

To plot a 3D trajectory, you will need to use a graphics library that supports 3D rendering, such as OpenGL or DirectX. These libraries have functions and methods for creating 3D objects and rendering them on a 3D coordinate system.

2. What data is needed to plot a 3D trajectory?

To plot a 3D trajectory, you will need the coordinates of the object at different points in time. This can be in the form of x, y, and z coordinates or polar coordinates (radius, azimuth, and elevation). You may also need the velocity and acceleration vectors if you want to show the movement of the object.

3. Can I customize the appearance of the 3D trajectory?

Yes, most graphics libraries have options for customizing the appearance of 3D objects. You can change the color, size, and shape of the trajectory, as well as add textures or lighting effects to make it more realistic.

4. How do I incorporate user input into the 3D trajectory plot?

You can incorporate user input by allowing them to control the movement of the object using keyboard or mouse inputs. This can be achieved by updating the coordinates of the object based on the user's input and re-rendering the 3D trajectory.

5. Can I export the 3D trajectory plot to other programs or file formats?

Yes, most graphics libraries have options for exporting the 3D trajectory plot to other programs or file formats. This allows you to use the plot in presentations, reports, or other software applications. You can export the plot as an image file or a 3D model file, depending on the capabilities of the library.

Similar threads

Replies
1
Views
792
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
7
Views
477
  • Programming and Computer Science
Replies
9
Views
2K
Replies
2
Views
881
  • STEM Academic Advising
Replies
12
Views
1K
  • Introductory Physics Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Programming and Computer Science
Replies
21
Views
1K
  • STEM Career Guidance
Replies
30
Views
5K
Back
Top