|
MAL.Subtract |
|
|
ref_arr_out = MAL.Subtract( BYREF arr_out AS ARRAY, BYREF arr_in1 AS ARRAY, BYREF arr_in2 AS ARRAY, [BYVAL nPoint AS INTEGER=ML_ALL], [BYVAL nFrameOffset AS INTEGER=0] ) AS REFERENCE
ref_arr_out = MAL.Subtract( BYREF arr_out AS ARRAY, BYREF arr_in AS ARRAY, BYREF nPoint1 AS INTEGER, BYVAL nPoint2 AS INTEGER, [BYVAL nFrameOffset AS INTEGER=0] ) AS REFERENCE
ref_arr_out = MAL.Subtract( BYREF arr_out AS ARRAY, BYREF arr_in AS ARRAY, [!] [BYVAL value AS REAL=0], [BYVAL nPoint AS INTEGER=ML_ALL], [BYVAL nFrameOffset AS INTEGER=0] ) AS REFERENCE
ref_arr_out = MAL.Subtract( BYREF arr_out AS ARRAY, BYREF arr_in AS ARRAY, [!] BYVAL valueX AS REAL, [BYVAL valueY AS REAL=valueX], [BYVAL nPoint AS INTEGER=ML_ALL], [BYVAL nFrameOffset AS INTEGER=0] ) AS REFERENCE
ref_arr_out = MAL.Subtract( BYREF arr_out AS ARRAY, BYREF arr_in AS ARRAY, [!] BYVAL valueX AS REAL, [BYVAL valueY AS REAL=valueX], [BYVAL valueZ AS REAL=valueX], [BYVAL nPoint AS INTEGER=ML_ALL], [BYVAL nFrameOffset AS INTEGER=0] ) AS REFERENCE
Adds one array to another and returns the resulting array as a reference. The 2 input arrays must be of same data type. The second syntax is used to subtract a scalar number to each of the input arrays index. If the array is a 2D or 3D array, you can specify a number for each dimension. This is useful when you want to calculate the relative motion to another static point.
Using the second syntax, the nPoint1 must be specified as an integer. You can use the function INT( n ) to force a number to be of type INTEGER. Note that the point ranges are not allowed using this syntax.
Important Note [!] You need to specify the X/Y/Z offsets to subtract in syntax 3, 4 and 5 as REAL otherwise the Libray will use it as a point number and use syntax 1 or 2. To make sure that the numbers are REAL, include at least 1 decimal or use the NUM function.
Example:
OPTION EXPLICIT ON OPTION BASE 1
' Include the MaxMAL Library $INCLUDE "MyBASIC2_MaxMAL" $LIBRARY "MyBASIC2_MaxMALLib"
' Forward Declare PrintArray DECLARE SUB PrintArray
' Declare variables and arrays CONST cPoints = 2 CONST cFrames = 10
DIM arrOut(cFrames,cPoints,3) AS REAL DIM arrIn1(cFrames,cPoints,3) AS REAL DIM arrIn2(cFrames,cPoints,3) AS REAL
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Initialize Arrays ' arrOut = 0 arrIn1 = 1 arrIn2 = 2
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Test MaxMAL Vector Algebra Functions ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' arrOut = arrIn1 + arrIn2 CALL PrintArray( MAL.Add( arrOut, arrIn1, arrIn2 ), "LET arrOut( 3 ) = arrIn1( 1 ) + arrIn2( 2 )" )
' arrOut = arrOut - arrIn1 CALL PrintArray( MAL.Subtract( arrOut, arrOut, arrIn1 ), "LET arrOut( 2 ) = arrOut( 3 ) - arrIn1( 1 )" )
' arrOut = arrOut - arrIn2 CALL PrintArray( MAL.Subtract( arrOut, arrOut, arrIn2 ), "LET arrOut( 0 ) = arrOut( 2 ) - arrIn2( 2 )" )
' arrOut = arrIn1 / arrOut -> #DIVBYZERO CALL PrintArray( MAL.Divide( arrOut, arrIn1, arrOut ), "LET arrOut( # ) = arrIn1( 1 ) / DIVBY0( 0 )" )
' arrOut = arrIn1 / arrIn2 CALL PrintArray( MAL.Divide( arrOut, arrIn1, arrIn2 ), "LET arrOut( 0.5 ) = arrIn1( 1 ) / arrIn2( 2 )" )
' arrOut = arrIn2 * arrOut CALL PrintArray( MAL.Multiply( arrOut, arrIn2, arrOut ), "LET arrOut( 1 ) = arrIn2( 2 ) * arrOut( 0.5 )" )
' arrOut = arrIn1 * 7.5 CALL PrintArray( MAL.Multiply( arrOut, arrIn1, 7.5 ), "LET arrOut( 7.5 = arrIn1( 1 ) * 7.5" )
' arrOut = arrOut / 2.5 CALL PrintArray( MAL.Divide( arrOut, arrOut, 2.5 ), "LET arrOut( 3 ) = arrOut( 7.5 ) / 3 " )
' arrOut = arrOut + 30 CALL PrintArray( MAL.Add( arrOut, arrOut, 30.0 ), "LET arrOut( 33 ) = arrOut( 30 ) + 3" )
' arrOut = arrOut - 30/40/50 CALL PrintArray( MAL.Subtract( arrOut, arrOut, 30.0, 40.0, 50.0 ), "LET arrOut( 3, -7, -17 ) = arrOut( 30 ) - POINT3D( 30, 40, 50 )" )
END
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Print an array with up to 3 dimensions. Array is passed as a reference ' SUB PrintArray( arr AS REFERENCE, msg AS STRING ) PRINT msg, RUN( "ArrayTable", arr, LEN( msg ) = 0 ) END SUB
|