This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Simulated and Actual Flight Data Using Aero.Animation Objects

Creating and Configuring an Animation Object

This series of commands creates an animation object and configures the object.

  1. Create an animation object.

    h = Aero.Animation;
  2. Configure the animation object to set the number of frames per second (FramesPerSecond) property. This configuration controls the rate at which frames are displayed in the figure window.

    h.FramesPerSecond = 10;
  3. Configure the animation object to set the seconds of animation data per second time scaling (TimeScaling) property.

    h.TimeScaling = 5;

    The combination of FramesPerSecond and TimeScaling property determine the time step of the simulation. These settings result in a time step of approximately 0.5 s.

  4. Create and load bodies for the animation object. This example uses these bodies to work with and display the simulated and actual flight trajectories. The first body is orange; it represents simulated data. The second body is blue; it represents the actual flight data.

    idx1 = h.createBody('','Ac3d');
    idx2 = h.createBody('','Ac3d');

    Both bodies are AC3D format files. AC3D is one of several file formats that the animation objects support. FlightGear uses the same file format. The animation object reads in the bodies in the AC3D format and stores them as patches in the geometry object within the animation object.

Loading Recorded Data for Flight Trajectories

This series of commands loads the recorded flight trajectory data, which is contained in files in the matlabroot\toolbox\aero\astdemos folder.

  • simdata – Contains simulated flight trajectory data, which is set up as a 6DoF array.

  • fltdata – Contains actual flight trajectory data which is set up in a custom format. To access this custom format data, the example must set the body object TimeSeriesSourceType parameter to Custom and then specify a custom read function.

  1. Load the flight trajectory data.

    load simdata
    load fltdata
  2. Set the time series data for the two bodies.

    h.Bodies{1}.TimeSeriesSource = simdata;
    h.Bodies{2}.TimeSeriesSource = fltdata;
  3. Identify the time series for the second body as custom.

    h.Bodies{2}.TimeSeriesSourceType = 'Custom';
  4. Specify the custom read function to access the data in fltdata for the second body. The example provides the custom read function in matlabroot\toolbox\aero\astdemos\CustomReadBodyTSData.m.

    h.Bodies{2}.TimeseriesReadFcn = @CustomReadBodyTSData;

Displaying Body Geometries in a Figure Window

This command creates a figure object for the animation object.;

Recording Animation Files

Enable recording of the playback of flight trajectories using the animation object.

h.VideoRecord = 'on';
h.VideoQuality = 50;
h.VideoCompression = 'Motion JPEG AVI'
h.VideoFilename = 'astMotion_JPEG';

Enable animation recording at any point that you want to preserve an animation sequence.


When choosing the video compression type, keep in mind that you will need the corresponding viewer software. For example, if you create an AVI format, you need a viewer such as Windows Media® Player to view the file.

After you play the animation as described in Playing Back Flight Trajectories Using the Animation Object, astMotion_JPEG contains a recording of the playback.

Playing Back Flight Trajectories Using the Animation Object

This command plays back the animation bodies for the duration of the time series data. This playback shows the differences between the simulated and actual flight data.;

If you used the Video properties to store the recording, see Viewing Recorded Animation Files for a description of how to view the files.

Viewing Recorded Animation Files

If you do not have an animation file to view, see Recording Animation Files.

  1. Open the folder that contains the animation file you want to view.

  2. View the animation file with an application of your choice.

    If your animation file is not yet running, start it now from the application.

  3. To prevent other commands from overwriting the contents of the animation file, disable the recording after you are satisfied with the contents.

    h.VideoRecord = 'off';

Manipulating the Camera

This command series shows how you can manipulate the camera on the two bodies and redisplay the animation. The PositionFcn property of a camera object controls the camera position relative to the bodies in the animation. In Playing Back Flight Trajectories Using the Animation Object, the camera object uses a default value for the PositionFcn property. In this command series, the example references a custom PositionFcn function that uses a static position based on the position of the bodies. No dynamics are involved.


The custom PositionFcn function is located in the matlabroot\toolbox\aero\astdemos folder.

  1. Set the camera PositionFcn to the custom function staticCameraPosition.

    h.Camera.PositionFcn = @staticCameraPosition;
  2. Run the animation again.;

Moving and Repositioning Bodies

This series of commands illustrates how to move and reposition bodies.

  1. Set the starting time to 0.

    t = 0;
  2. Move the body to the starting position that is based on the time series data. Use the Aero.Animation object Aero.Animation.updateBodies method.

  3. Update the camera position using the custom PositionFcn function set in the previous section. Use the Aero.Animation object Aero.Animation.updateCamera method.

  4. Reposition the bodies by first getting the current body position, then separating the bodies.

    1. Get the current body positions and rotations from the objects of both bodies.

      pos1 = h.Bodies{1}.Position;
      rot1 = h.Bodies{1}.Rotation;
      pos2 = h.Bodies{2}.Position;
      rot2 = h.Bodies{2}.Rotation;
    2. Separate and reposition the bodies by moving them to new positions.

      h.moveBody(1,pos1 + [0 0 -3],rot1);
      h.moveBody(2,pos1 + [0 0  0],rot2);

Creating a Transparency in the First Body

This series of commands illustrates how to create and attach a transparency to a body. The animation object stores the body geometry as patches. This example manipulates the transparency properties of these patches (see Patch Properties).


The use of transparencies might decrease animation speed on platforms that use software OpenGL® rendering (see opengl).

  1. Change the body patch properties. Use the Aero.Body PatchHandles property to get the patch handles for the first body.

    patchHandles2 = h.Bodies{1}.PatchHandles;

  2. Set the face and edge alpha values that you want for the transparency.

    desiredFaceTransparency = .3;
    desiredEdgeTransparency = 1;
  3. Get the current face and edge alpha data and change all values to the alpha values that you want. In the figure, the first body now has a transparency.

    for k = 1:size(patchHandles2,1)
        tempFaceAlpha = get(patchHandles2(k),'FaceVertexAlphaData');
        tempEdgeAlpha = get(patchHandles2(k),'EdgeAlpha');

Changing the Color of the Second Body

This series of commands illustrates how to change the color of a body. The animation object stores the body geometry as patches. This example manipulates the FaceVertexColorData property of these patches.

  1. Change the body patch properties. Use the Aero.Body PatchHandles property to get the patch handles for the first body.

    patchHandles3 = h.Bodies{2}.PatchHandles;

  2. Set the patch color to red.

    desiredColor = [1 0 0];
  3. Get the current face color and data and propagate the new patch color, red, to the face.

    • The if condition prevents the windows from being colored.

    • The name property is stored in the body geometry data (h.Bodies{2}.Geometry.FaceVertexColorData(k).name).

    • The code changes only the indices in patchHandles3 with nonwindow counterparts in the body geometry data.


      If you cannot access the name property to determine the parts of the vehicle to color, you must use an alternative way to selectively color your vehicle.

    for k = 1:size(patchHandles3,1)
        tempFaceColor = get(patchHandles3(k),'FaceVertexCData');
        tempName = h.Bodies{2}.Geometry.FaceVertexColorData(k).name;
        if isempty(strfind(tempName,'Windshield')) &&...
           isempty(strfind(tempName,'front-windows')) &&...

Turning Off the Landing Gear of the Second Body

This command series illustrates how to turn off the landing gear on the second body by turning off the visibility of all the vehicle parts associated with the landing gear.


The indices into the patchHandles3 vector are determined from the name property. If you cannot access the name property to determine the indices, you must use an alternative way to determine the indices that correspond to the geometry parts.

for k = [1:8,11:14,52:57]