Page 1 of 1

How to exactly rotate the data in Tables

Posted: Wed Sep 02, 2020 8:40 pm
by nikorose
Hi all,

I am trying to replicate the osimC3D script made by you in Matlab into python, especifically I am building the

Code: Select all

rotateTable
function to rotate some axis in the markers and force tables. I have the following code:

Code: Select all

    def rotateTable(self, table, axisString, value):
        value_rad = np.deg2rad(value)
        #set up the transform
        if axisString == 'x':
            axis = simb.CoordinateAxis_getCoordinateAxis(0)
        elif axisString == 'y':
            axis = simb.CoordinateAxis_getCoordinateAxis(1)
        elif axisString == 'z':
            axis = simb.CoordinateAxis_getCoordinateAxis(2)
        
        #Rotation() works on each row.
        R = simb.Rotation_setRotationFromAngleAboutAxis(value_rad, axis)
        for iRow in range(table.getNumRows()):
            #get a row from the table
            rowVec = table.getRowAtIndex(iRow)
            rowVec_rotated = simb.Rotation_multiply(R, rowVec)
            table.setRowAtIndex(iRow,rowVec_rotated)
        return table
Running the script a ValueError is raised:

R = simb.Rotation_setRotationFromAngleAboutAxis(value_rad, axis)

TypeError: Rotation_setRotationFromAngleAboutAxis() takes exactly 3 arguments (2 given)


This is asking for three arguments. However, in the API documentation is indicated that only two arguments are needed.

Can you please let me know how to call the Rotation function in the API to set an angle for rotation, to set the axis of rotation and, to multiply by a row vector.

Re: How to exactly rotate the data in Tables

Posted: Fri Sep 04, 2020 12:17 am
by mitkof6
Hi,

You can do the following:

Code: Select all

def rotate_data_table(table, axis, deg):
    """Rotate OpenSim::TimeSeriesTableVec3 entries using an axis and angle.

    Parameters
    ----------
    table: OpenSim.common.TimeSeriesTableVec3

    axis: 3x1 vector

    deg: angle in degrees

    """
    R = opensim.Rotation(np.deg2rad(deg),
                         opensim.Vec3(axis[0], axis[1], axis[2]))
    for i in range(table.getNumRows()):
        vec = table.getRowAtIndex(i)
        vec_rotated = R.multiply(vec)
        table.setRowAtIndex(i, vec_rotated)


Re: How to exactly rotate the data in Tables

Posted: Sun Sep 06, 2020 8:24 am
by nikorose
Thanks Dimitar, It is working