User:Eml4500.f08.team.foskey.ckf/hw7e

Animation of the modes from the elecric pylon truss

Animation Problem
In this problem, the mode plots from the original truss problem are to be animated. In order to accomplish this, the old code is reused. A new MATLAB code (shown later in this page) animates the modes using the information from the old code.

To run the Animation Code, the following MATLAB m-files are required:

electric_pylon.m (original provided code) solvingpylon1.m (loading code) solvingpylon2.m (lumped mass code) PlaneTrussElement.m (function) PlaneTrussResults.m (function) NodalSoln.m (function) TransientPlaneTrussElement.m (function)

All of the above files can be found in the Electric Pylon Truss Problem.

Matlab Code (Animation Code)
The following MATLAB code is used to create the frames that will be used to make the animations

Comments On The Animation Code
The animation code begins by running the original electric pylon truss code for finding the modes "solvingplyon2.m". This loads all of the needed data. Next the number of frames is selected, in this case "N=8". The next lines are critical to how the code works. In the lines:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% choose=3;  %select which mode to animate (1,2 or 3) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

the user must manually select which mode to animate. This saves time when running the code, as 16 images will be displayed for each mode. It also saved time when writing the code. The lines following the selection display the only output for this code, which is information regarding the number of frames, and which mode is being animated. The next sections of the code are essentially the same concept repeated three times, once for each mode. There are three "if" statements that check which mode is being animated, and then use the necessary data from "solvingpylon2.m".

In each mode loop, the vibrational period is divided by the number of frames to obtain increments of the period. A matrix del is created to hold the steadily increasing increments (cell 1 of del is one segment, cell 2 is two segments, and cell 8 is eight segments, or the full vibrational period).

Next, partial modes are created by looping through the number of frames and creating a column matrix of partial modes based on del. All of the partial modes are put into a single matrix, in which the next partial mode begins as the previous one ends. A scaling factor of 1,000,000,000 is also created here.

Next, the code plots the original undeformed truss. Then the deformed truss is plotted by adding the partial modes as displacements to the nodal coordinates (this will be referred to as a "positive deformation"). This is repeated for all eight frames, with each figure showing a slightly more deformed truss. Each figure is saved as a frame using MATLAB's getframe code.

This process is repeated again for eight frames, this time subtracting the partial modes from the original nodal coordinates (referred to as "negative" deformation). Doing this results in 16 frames, 8 of which show the truss moving in one direction, 8 show it moving in the opposite.

The above code process is repeated for all three modes, only one of the three will actually run when the code is run, based upon the user's input as to which mode should be animated.

To better show the animation, there will be 24 images in one mode animation cycle. The first eight image frames will be the truss moving from undeformed to a "positive deformation". The next eight are the first eight in reverse order so that the truss returns to its undeformed shape. The next eight images will show the truss undergoing "negative deformation", and the final eight images show the truss returning to its original shape.

The above is accomplished by using loops and hard coding to assign the image frames to their proper order to create a 24 frame video.

A "close all" statement is seen in the last few lines. This is commented out in the above code because the figures were needed for saving purposes (as explained later in the animations section). For a more efficient code, this line should be left in place to close the open figures.

The line "movie(H,3)" of the code will play the animation in MATLAB. This animation will loop through 3 cycles of the 24 frame animation.

Three "if" statements end the code, each creating a video file based on the mode chosen by the user. This is done using MATLAB's movie2avi code.

In order to obtain complete results, the user must run this code three times, each time changing the value of the variable "choose" to 1, 2 and 3. The user will then have three avi videos in their MATLAB directory folder entitled mode1animate.avi, mode2animate.avi, and mode3animate.avi.

Animations
The above MATLAB mode code will create three avi videos for the truss modes. Each of these can be opened with a media player, such as Windows Media Player. However, MediaWiki does not allow for the uploading of avi files.

In order to upload the animations, they must be converted to a different format, such as GIF. In order to do this, each image frame needed to be saved as its own file. This was done by manually saving each figure created by MATLAB as a tiff file. For each mode there are 16 different images, each representing one frame of the final animation.

The images were put together in their proper order and made into a single gif file by using Photoshop.