Code covered by the BSD License  

Highlights from
Fly a 747 using MATLAB

image thumbnail

Fly a 747 using MATLAB

by

 

16 Dec 2009 (Updated )

Animate the motion of a 747 along a helical path all from within MATLAB.

Plane_Helix.m
% Clean the variables 
clear all;

% Define the parameter t
n=4;
t=0:0.02:n*pi;

% Define a and b
a=8;
b=1;

% Access the 3D World from MATLAB
world=vrworld('my_plane.wrl', 'new');
open(world);
fig=vrfigure(world);
set(fig, 'Viewpoint', 'Far View');
airpln=vrnode(world, 'Plane');
vector_z=[0 0 1];

% Create the simulation loop
for i=1:length(t)
    pause (0.01);
    vector_position=[a*cos(t(i)) b*t(i) a*sin(t(i))];
    % Translation setting for the Plane node
    airpln.translation=vector_position;
    % Compute the cross product and the amount of rotation theta
    vector_velocity=[-a*sin(t(i)) b a*cos(t(i))];
    vector=cross(vector_velocity, vector_z);
    vector=vector/norm(vector);
    theta=acos(dot(vector_velocity, vector_z)/(norm(vector_velocity)*norm(vector_z)));
    % Rotation setting for the Plane node
    airpln.rotation=[vector -theta];
    % Update the figure
    vrdrawnow;
end

% Exit gracefully
pause;
close(world)
delete(world)


Contact us