Rotating an object around it's origin after translation

Hi!
I want to translate my object and then rotate it around the translated origin not the main origin of the page’s coordinate.I don’t know how i can solve the problem. can any one help me?(my code is shown below)

  • the code in the translation function is this:
    vtkSmartPointer<vtkTransformFilter> transformFilter = vtkSmartPointer<vtkTransformFilter>::New();
    transformFilter->SetInputData(updatedPolydata);

    vtkSmartPointer<vtkTransform> translation = vtkSmartPointer<vtkTransform>::New();
    translation->Translate(tx, ty, tz);
    translation->Update();

    transformFilter->SetTransform(translation);
    transformFilter->Update();

    vtkSmartPointer<vtkPolyData> translatedSTL = transformFilter->GetPolyDataOutput();

    mapper->SetInputData(translatedSTL);
    mapper->Update();
    actor->SetMapper(mapper);
  • the code in the rotation function is this:
    vtkSmartPointer<vtkTransform> rotation = vtkSmartPointer<vtkTransform>::New();
    rotation->RotateX(x_degree);
    rotation->RotateY(y_degree);
    rotation->RotateZ(z_degree);
    rotation->Update();

    vtkSmartPointer<vtkTransformFilter> rotationFilter = vtkSmartPointer<vtkTransformFilter>::New();
    rotationFilter->SetInputData(updatedPolydata);
    rotationFilter->SetTransform(rotation);
    rotationFilter->Update();

    vtkSmartPointer<vtkPolyData> rotatedSTL = rotationFilter->GetPolyDataOutput();

    mapper->SetInputData(rotatedSTL);
    mapper->Update();
    actor->SetMapper(mapper);

sorry, it’s necessary for me to find the answer.can you help me?
@mwestphal

Hi @kimia_ghodoosi

If you need a fast and necessary answer, please contact Kitware directly for professional support:

Best,

Hello,

You are applying two independent transforms (two vtkTransform objects). You need to composite them as a single vtkTransform to rotate an object about an arbitrary center. To rotate something about a center not in the global origin (e.g. (42,42,42)), you need, first, to translate A=(-42,-42,-42) towards the origin; then rotate about the origin (R), then undo the translation back to the correct location B=(+42,+42,+42). Pay attention to multiply the transform matrices in the correct order: the matrix product must be B*R*A and not A*R*B. The first transform to be applied is the last one in the multiplication order.

regards,

PC

1 Like

Thank you so much Paulo. my problem solved with your solution.

1 Like

Please, I recommend a nice book called “Graphics Gems”. It’s 9th chapter delves into the linear algebra necessary for computer graphics. It’s a 1990 book, but if you want to even write you own graphics engine, it’s still worth it.

take care,

PC

Could you recommend a book only one or two years old to learn the newest trends in computer graphics (or GLSL)?

Hmmm… “Graphics Gems” is not a book on an outdated topic. It’s on how to design a graphics system. There’s nothing trendy about that: you either know or do not know how to design a graphics engine. GLSL is a technology, for that you find plenty of materials readily available on the internet such as this OpenGL 1k-page book (includes a shader/GLSL primer) in PDF format: https://www.cs.utexas.edu/users/fussell/courses/cs354/handouts/Addison.Wesley.OpenGL.Programming.Guide.8th.Edition.Mar.2013.ISBN.0321773039.pdf . You may also want to read this VTK primer from KitWare itself: https://gitlab.kitware.com/vtk/textbook/raw/master/VTKBook/VTKTextBook.pdf .

best,

PC

1 Like