Вы находитесь на странице: 1из 9

12/12/2013

747 Project
Chemical and Process Engineering

Raymond Ward

Yvan Pierre #813001012
Anil Toolsie #813001422
Anuradha Phagoo #813117229
Aldo Moreau #813001167

1 | P a g e

Abstract
In order to code for the trajectory of a 747 airliner in MATLAB, the velocity equations
were defined. This gives an indication of the plane changing direction along a specified path.
This path was further defined through the use of rigid body descriptors; namely in terms of
rotation and translations. This was accomplished by looking at the system in terms of vectors.
When the code was run however, there was a 360 rotation at certain points in the planes
trajectory. This was resolved by the use of quaternions applied to the 3-dimensional space.
2 | P a g e

Body
Velocity equations

In order to have the Boeing 747 aircraft travel along a helical path in Matlab, its
trajectory needs to be defined. Consider a 3-dimensional coordinate system, (x, y, z). Its
trajectory can be best expressed parametrically as x, y and z coordinates in terms of the variable,
t.
x = acos(t)
y = bt
z = asin(t)
Where a= radius of rotation and b= height increased per turn
The velocity of the plane can then be expressed as the differential of the displacement
equations, as follows.
dx/dt = -asin(t),
dy/dt = b
dz/dt = acos(t) for 0t n

Rigid body descriptors

Translation
The vector around which the rotation is taking place, is given the symbol . This vector
takes the value of the cross product between the rotational vector and the z axis. The cross
product of two vectors, yields another vector that is orthogonal (at 90) to both vectors crossed.
As such, when the rotational vector and the z axis are crossed, it gives the vector around which
the rotation takes place.

= cross([-asin(t), 0, acos(t)], [0,0,1]) & = cos
-1
(dot([Asin(t),0,Acos(t)],[0,0,1]))/A



3 | P a g e

Rotation
The angle at which the rotation takes place around the said vector, is given the symbol
. takes the value of the dot product of the velocity vector and the z axis.

Matlab code showing 360 flip

% 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('C:\Users\Yvan\Downloads\Fly_747\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;
4 | P a g e

close(world)
delete(world)


Explanation of how the code was made to work

The relevant code for the 747 project was obtained from the MATLAB source code
database. The code needed some adjustments before the simulation would run as it should.
Firstly, we needed to create a virtual world in V Realm. This involved starting the builder and
opening a new, blank world. A 3D model of a Boeing 747 plane was inserted into the world, by
searching for the plane in the object library of V Realm. A background was then added by
clicking its icon and two viewpoints were also created. One viewpoint represented the far view
of the plane that would be used to observe its trajectory as it ran. Such a point of view was
achieved by adjusting the position parameters to 0:0:45 of which was in the form x: y: z. The
other viewpoint was labelled the top view and was created by changing the parameters to 1:60:0
and the orientation was adjusted to -1:0:0 and a rotation of -90 was applied.
Once the world was completed, it was saved onto the hard drive of the computer. The file
path for the world was then determined and referenced in the source code of the program, so that
the world would open properly once the program was run. The source code along with the
corrected file path for the world was added to a blank script and ran. The plane successfully
moved in the helical nature as described by our equations.

Corrected code involving the use of quaternions

clear all;
t = 0: 0.02*pi : 4*pi;
a = 10; b = 2;

world = vrworld('C:\Users\Yvan\Downloads\terrain\terrain\terrain.wrl', 'new');
open(world);
fig = vrfigure(world);
airplane= vrnode(world, 'Aircraft');
set(fig, 'Viewpoint', 'Long View');
% vector_3=[0 0 1];

% get the path to the wrl file with marker PROTOs
pathtomarkers = which('vr_markers.wrl');
% use the tetrahedron shape
5 | P a g e

MarkerName = 'Marker_Sphere';
% create an EXTERNPROTO with specified marker
try
addexternproto(world, pathtomarkers, MarkerName);
catch ME
% if required PROTO is already contained don't throw an exception
if ~strcmpi(ME.identifier, 'VR:protoexists')
throwAsCaller(ME);
end
end


for i=1:length(t)
pause(0.1);
vector_1=[a*cos(t(i)) b*t(i) a*sin(t(i))];
vector_2=[-a*sin(t(i)) b a*cos(t(i))];
dcm_component_x=-[-a*cos(t(i)) 0 -a*sin(t(i))];
dcm_component_x=dcm_component_x/sqrt(dot(dcm_component_x,dcm_component_x));
dcm_component_z=vector_2/sqrt(dot(vector_2,vector_2));
dcm_component_y=cross(dcm_component_z,dcm_component_x);
dcm=[dcm_component_x' dcm_component_y' dcm_component_z'];
quat=dcm2quat(dcm);
quat=quatnormalize(quat);
theta= 2*acos(quat(1,1));

if theta ~=0
vector=[quat(1,2) quat(1,3) quat(1,4)]/sin(theta/2);
else
vector=[0 0 0];
end

%vector_cross(i,:)=cross(vector_2, vector_3);
%angle_cosine(i)=acos(dot(vector_2, vector_3)/(norm(vector_2)*norm(vector_3)));
airplane.translation=vector_1;
airplane.rotation=[vector -theta];
newMarker = vrnode(world, sprintf('%s_%d', 'Marker', i), MarkerName);
newMarker.markerTranslation = vector_1(1:3);
newMarker.markerScale=[0.3 0.1 0.1];
newMarker.markerColor=[255 255 240];
%vector_3=vector_2;
vrdrawnow;
end

% Exit gracefully
close(fig)
close(world)
6 | P a g e

Explanation of why the plane flipped and how our solution works

The Boeing 747 made a 360 flip due to the fact that we were not using quaternions.
Quaternions are a number system which extends the complex numbers and that can be applied to
3 dimensional space. By using quaternions, we avoid the problem caused by gimbal lock.
Gimbal lock is the loss of one degree of freedom in three dimensional, three-gimbal mechanism
that occurs when the axes of two of the three gimbals become parallel, locking the system into
rotating in a 2 dimensional space. A quaternion is a tuple made of 4 numbers (s, x, y, z) of which
the sum of their squares when equal to 1, verifies the quaternion and allows for its use to
represent rotation. The rotation of an angle around an axis directed by the normalized vector
N=(x
0
, y
0
, z
0
) is represented by the quaternion [cos (/2), x
0
. sin (/2), y
0
. sin (/2), z
0
. sin (/2)].
In our simulation, the x and z axis became parallel once the angle rotated was equal to .
At this moment the y axis is forced to make a 360 degree flip due to the conditions which caused
a gimbal lock.










7 | P a g e


Conclusion

The objective of the experiment was to explain why the 747 plane made a 360 degree
flip, this objective was successfully met since the velocity equations and the rigid body
descriptors were explained in detailed. In addition, the Matlab code used for the 747 project was
produced and a brief explanation of it was provided.






























8 | P a g e

References

"Fly a 747 with MATLAB." - Simulink Video. http://www.mathworks.com/videos/fly-a-
747-with-matlab-68730.html (accessed December 11, 2013).
Fly a 747 with MATLAB: Adding Realism, Quaternions, Trajectory Tracing - Simulin
Video. http://www.mathworks.com/matlabcentral/fileexchange/27986-fly-a-747-with-
matlab-adding-realism-quaternions-trajectory-tracing.html (accessed December 11,
2013).
Using Quaternion to perform 3D rotations. Quaternions and 3D Rotations.
http://www.cprogramming.com/tutorial/3d/quaternions.html (accessed December 12,
2013).

Вам также может понравиться