File: ef230-2023-08/www/examples/kick3d.m Download
%| Demo of how to show a 3D trajectory on an image
%  University of Tennessee : EF 230, Fall, 2009 : Will Schleter

clear all; close all; clc;

% set up a 3D plot
view(3);
title('Kick');
hold on;
set(gca,'ydir','reverse');
axis([-75 75 0 360]);
axis image
%axis off
axis square
axis image

% show the 'field'
img_fb=imread('http://www.therugs.com/images/JOYC/KDE/1471_FootballFun.jpg');
[x,y]=meshgrid([-75 75],[0 360]);
z=zeros(size(x));
surf(x,y,z,'facecolor','texturemap','CData',img_fb);

% calculate a trajectory in x and z
x0=60;
z0=0;
v=70;
shootang=45;
vx0=v.*cosd(shootang);
vz0=v.*sind(shootang);
az=-32.2;
xpoly=[vx0 x0];
zpoly=[az/2 vz0 z0];
thit=max(roots(zpoly)); % time to hit the ground
t=linspace(0,thit,700);
x=polyval(xpoly,t);
z=polyval(zpoly,t);

% rotate about z axis
rotang=100;
y=x.*sind(rotang);
x=x.*cosd(rotang);

% display the animated trajectory
comet3(x,y,z);