3D rotation matrix between 2 axis

asked 2015-07-16 05:18:00 -0600

maystroh10 gravatar image

updated 2015-07-16 09:11:56 -0600

I have 2 known 3d points which are the origin of 2 axis plot in the space and I need to compute the 3D rotation matrix between them. I didn't really get what the difference Euler angles and the other type of angles? Any help please?

EDITED:

image description

I have Oc1 and Oc2 known points in the space and I know that using R1&T1 I can get to Oc1 and using R2&T2 I can get to Oc2 but I need to compute the 3D rotation matrix between Oc1 and Oc2. Is there any openCV method that computes such rotation?

EDITED Here my code for a sample to test c1Mc2 = (oMc1)^-1 oMc2:

vector <Point3f> listOfPointsOnTable;
    cout << "******** DATA *******" << endl;
    listOfPointsOnTable.push_back(Point3f(0,0,0));
    listOfPointsOnTable.push_back(Point3f(100,0,0));
    listOfPointsOnTable.push_back(Point3f(100,100,0));
    listOfPointsOnTable.push_back(Point3f(0,100,0));

    cout << endl << "Scene points :" << endl;
    for (int i = 0; i < listOfPointsOnTable.size(); i++)
    {
        cout << listOfPointsOnTable[i] << endl;
    }

    //Define the optical center of each camera
    Point3f centreOfC1 = Point3f(23,0,50);
    Point3f centreOfC2 = Point3f(0,42,20);
    cout << endl << "Center Of C1: " << centreOfC1 << " , Center of C2 : " << centreOfC2 << endl;

    //Define the translation and rotation between main axis and the camera 1 axis
    Mat translationOfC1 = (Mat_<double>(3, 1) << (0-centreOfC1.x), (0-centreOfC1.y), (0-centreOfC1.z));
    float rotxC1 = 0, rotyC1 = 0, rotzC1 = -45;
    int focaleC1 = 2;
    Mat rotationOfC1 = rotation3D(rotxC1, rotyC1,rotzC1);
    cout << endl << "Translation from default axis to C1: " << translationOfC1 << endl;
    cout << "Rotation from default axis to C1: " << rotationOfC1 << endl;
    Mat transformationToC1 = buildTransformationMatrix(rotationOfC1, translationOfC1);
    cout << "Transformation from default axis to C1: " << transformationToC1 << endl << endl;

    //Define the translation and rotation between main axis and the camera 2 axis
    Mat translationOfC2 = (Mat_<double>(3, 1) << (0-centreOfC2.x), (0-centreOfC2.y), (0-centreOfC2.z));
    float rotxC2 = 0, rotyC2 = 0, rotzC2 = -90;
    int focaleC2 = 2;
    Mat rotationOfC2 = rotation3D(rotxC2, rotyC2,rotzC2);
    cout << endl << "Translation from default axis to C2: " << translationOfC2 << endl;
    cout << "Rotation from default axis to C2: " << rotationOfC2 << endl;
    Mat transformationToC2 = buildTransformationMatrix(rotationOfC2, translationOfC2);
    cout << "Transformation from default axis to C2: " << transformationToC2 << endl << endl;

    Mat centreOfC2InMat = (Mat_<double>(3, 1) << centreOfC2.x, centreOfC2.y, centreOfC2.z);
    Mat centreOfC2InCamera1 = rotationOfC1 * centreOfC2InMat + translationOfC1;
    Mat translationBetweenC1AndC2 = -centreOfC2InCamera1;
    cout << endl << "****Translation from C2 to C1" << endl;
    cout << translationBetweenC1AndC2 << endl;
    Mat centreOfC1InMat = (Mat_<double>(3, 1) << centreOfC1.x, centreOfC1.y, centreOfC1.z);
    Mat centreOfC1InCamera2 = rotationOfC2 * centreOfC1InMat + translationOfC2;
    Mat translationBetweenC2AndC1 = -centreOfC1InCamera2;
    cout << "****Translation from C1 to C2" << endl;
    cout << translationBetweenC2AndC1 << endl;

    cout << "Tran1-1 * Trans2 = " << transformationToC1.inv() * transformationToC2 << endl;
    cout << "Tran2-1 * Trans1 = " << transformationToC2.inv() * transformationToC1 << endl;

Mat rotation3D(int alpha, int beta, int gamma)
{
    // Rotation matrices around the X, Y, and Z axis
    double alphaInRadian = alpha * M_PI / 180.0;
    double betaInRadian = beta * M_PI / 180.0;
    double gammaInRadian = gamma * M_PI / 180.0;
    Mat RX = (Mat_<double>(3, 3) <<
                  1,          0,           0,
                  0, cosf(alphaInRadian), sinf(alphaInRadian),
                  0, -sinf(alphaInRadian),  cosf(alphaInRadian));
    Mat RY = (Mat_<double>(3, 3) <<
                  cosf(betaInRadian), 0, sinf(betaInRadian),
                  0, 1,          0,
                  -sinf(betaInRadian), 0,  cosf(betaInRadian));
    Mat RZ = (Mat_<double>(3, 3) <<
                  cosf(gammaInRadian), sinf(gammaInRadian), 0 ...
(more)
edit retag flag offensive close merge delete

Comments

I don'y really get it. you have two axis that intersect at the origin and you want a 3d rotation between both? This is not well posed as your setup only defines two angles.

FooBar gravatar imageFooBar ( 2015-07-16 06:05:44 -0600 )edit

Does this helps you understand the Euler angles? Anyway, this is not an OpenCV question...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-16 06:22:53 -0600 )edit

@Edited question.

maystroh10 gravatar imagemaystroh10 ( 2015-07-16 06:46:30 -0600 )edit

Th docs are here, or opencv 3.0 ones

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-16 06:59:34 -0600 )edit

You have oMc1=(R1 | T1) and oMc2=(R2 | T2) and what you want is:

c1Mc2 = (oMc1)^-1 oMc2
Eduardo gravatar imageEduardo ( 2015-07-16 07:20:01 -0600 )edit

I know but I don't see something related I can use it to do what I want.

maystroh10 gravatar imagemaystroh10 ( 2015-07-16 07:26:33 -0600 )edit

It's just matrix multiplication, you should look at the documentation, or here...

Eduardo gravatar imageEduardo ( 2015-07-16 07:33:19 -0600 )edit

@edited question

maystroh10 gravatar imagemaystroh10 ( 2015-07-16 08:17:18 -0600 )edit