How to exactly rotate the data in Tables

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Edwin Prieto
Posts: 9
Joined: Wed Jun 26, 2013 6:09 pm

How to exactly rotate the data in Tables

Post by Edwin Prieto » Wed Sep 02, 2020 8:40 pm

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.

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: How to exactly rotate the data in Tables

Post by Dimitar Stanev » Fri Sep 04, 2020 12:17 am

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)


User avatar
Edwin Prieto
Posts: 9
Joined: Wed Jun 26, 2013 6:09 pm

Re: How to exactly rotate the data in Tables

Post by Edwin Prieto » Sun Sep 06, 2020 8:24 am

Thanks Dimitar, It is working

POST REPLY