MAL.Acceleration |
![]() ![]() |
ref_arr_out = MAL.Acceleration( [BYREF arr_out AS ARRAY], BYREF arr_in AS ARRAY, [BYVAL nLength AS INTEGER=2], [BYVAL nPoint AS INTEGER=ML_ALL], [BYVAL nFrameOffset AS INTEGER=0] ) AS REFERENCE
Calculates the acceleration of the data supplied in the input array. The nLength parameter determines the number of frames it skips over for the acceleration calculation. This creates a way of applying a smoothing filter to the data. The longer the length, the smoother the data. The default is 2, meaning it's skipping 1 sample for each calculation. See table below. Since acceleration is the 2nd derivative, it calculates the velocity first before it calculates the acceleration.
To set the Frame rate (fequency) used to calculate the acceleration, call the MAL.FrameRate function.
Table Showing Frames used with nLength 2
Example:
OPTION EXPLICIT ON OPTION BASE 1
' Include C3D Support $INCLUDE "MyBASIC2_C3DFile" $LIBRARY "MyBASIC2_C3DFileLib"
' Needed to extract and Display Version $LIBRARY "MyBASIC2_ExtLib"
' Include the MaxMAL Library $INCLUDE "MyBASIC2_MaxMAL" $LIBRARY "MyBASIC2_MaxMALLib"
' Forward Declare PrintArray and DisplayVersion DECLARE SUB PrintArray DECLARE SUB DisplayVersion
' Declare variables and arrays DIM nPoints AS INTEGER DIM nFrames AS INTEGER DIM hFile AS INTEGER
' Test File CONST cFileName = "e:\walk8.c3d"
' Display the current Library Version CALL DisplayVersion()
' Open the Test File hFile = C3DFile.Open( cFileName )
IF NOT hFile > 0 THEN PRINT "Error Opening File ";cFileName, STOP ENDIF
' Get the no of points and frames nFrames = C3DFile.GetNoOfFrames( hFile ) nPoints = C3DFile.GetNoOfPoints( hFile )
' Dimension the arrays DIM Position(nFrames,nPoints,3) AS REAL DIM Velocity(nFrames,nPoints,3) AS REAL DIM Acceleration(nFrames,nPoints,3) AS REAL
' Get the Point Coordinates from C3D file IF C3DFile.GetPoints( hFile, Position ) <> nFrames THEN C3DFile.Close( hFile ) PRINT "Error Reading ";nPoints;" from file ";cFileName, STOP ENDIF
' Set the Frame Rate to use in the MaxMAL Library MAL.FrameRate( C3DFile.GetFrameRate( hFile ) )
' Display the Position Coordinates CALL PrintArray( REF( Position ) )
' Calculate and Display Velocity MAL.Velocity( Velocity, Position ) CALL PrintArray( REF( Velocity ) )
' Calculate and Display Acceleration MAL.Acceleration( Acceleration, Position ) CALL PrintArray( REF( Acceleration ) )
' Close File C3DFile.Close( hFile )
END
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Print an array with up to 3 dimensions. Array is passed as a reference ' SUB PrintArray( arr AS REFERENCE ) RUN( "ArrayTable", arr, TRUE ) END SUB
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Display the MaxMAL Extension Library Version ' SUB DisplayVersion() DIM major AS INTEGER DIM minor AS INTEGER DIM build AS INTEGER DIM qfe AS INTEGER
major = BYTE.HI( WORD.HI( MAL.Version() ) ) minor = BYTE.LO( WORD.HI( MAL.Version() ) ) build = BYTE.HI( WORD.LO( MAL.Version() ) ) qfe = BYTE.LO( WORD.LO( MAL.Version() ) )
PRINT "Library Version: ";FORMAT( "%d, %d, %d, %d", major, minor, build, qfe ), PRINT "Option Flags: ";FORMAT( "0x%08X", MAL.Version( TRUE ) ), END SUB
|