# Translate Object in Python

**URL:** https://discourse.vtk.org/t/translate-object-in-python/13436
**Category:** Support
**Tags:** python
**Created:** [March 4, 2024, 2:00pm UTC](https://discourse.vtk.org/t/translate-object-in-python/13436 "2024-03-04T14:00:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![cam](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@cam](https://discourse.vtk.org/u/cam)
#### Post date: [March 4, 2024, 2:00pm UTC](https://discourse.vtk.org/t/translate-object-in-python/13436/1 "2024-03-04T14:00:08Z")

</div>

Hey all, I hope all is well.

I’m looking for some help with translating my 3D object. For some context, I need to translate my 3D object in order for a matrix rotation to apply at the correct location, but I’m having trouble getting that to happen. I looked at [this](https://vtk.org/doc/nightly/html/classvtkTransform.html#a9a6bcc6b824fb0a9ee3a9048aa6b262c) page to explain how the transform class work, but my render isnt properly showing it.

Here is what I currently have:

```auto
        # Instance of OpenGL Class
        vtkWidget = QVTKRenderWindowInteractor(self.uic.openGLViewer)
        vtkWidget.setGeometry(0, 0, 481, 341)

        vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        iren = self.vtkWidget.GetRenderWindow().GetInteractor()
        iren.SetInteractorStyle(NoneInteractorStyle())

        reader = vtkSTLReader()
        reader.SetFileName(filename)

        # Create a mapper
        mapper = vtkPolyDataMapper()
        mapper.SetInputConnection(reader.GetOutputPort())

        # Create an actor
        actor = vtkActor()
        actor.SetMapper(mapper)

        ren.AddActor(self.actor)
        ren.SetBackground(0.1, 0.1, 0.1)
        ren.ResetCamera()
        ren.GetActiveCamera().Zoom(0.8)

        # Matrix 
        vtk_matrix = vtk.vtkTransform
        vtk_matrix.Translate(0, 1000, 0)
        actor.SetUserMatrix(vtk_matrix)
        
        ren.Render()
                    

```

None interactor is a custom class meant to prevent the user from being able to rotate the object with the mouse. I want the backend to handle all of it’s rotations.

```auto
# Prevents mouse movements from moving visual 
class NoneInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):
    def __init__ (self):
        self.SetKeyPressActivation(False)
        self.SetMouseWheelMotionFactor(0)
        self.SetMotionFactor(0)

```

When ran, the object isn’t translate in any way.

Thanks in advance!

Edit:  
Here is how I was able to apply the translation, but it didn’t apply my rotation to a different point on my model.

```auto
                    # Gyro values 
                    gyroX = 0 #float(line[4]) + gyroX_old
                    gyroY = -float(line[5]) + gryoY_old
                    gyroZ = float(line[6]) + gyroZ_old

                    # Integration
                    gyroX_old = gyroX
                    gryoY_old = gyroY
                    gyroZ_old = gyroZ

                    # Matrix 

                    rotation_matrix = euler_to_rotation_matrix(np.radians(round(gyroZ, 2)), np.radians(round(gyroX, 2)), np.radians(round(gyroY, 2)))
                    vtk_matrix = rotation_matrix_to_vtk(rotation_matrix)

                    translation = vtk.vtkTransform()
                    translation.Translate(0, 100, 0)
                    
                    transform = vtk.vtkTransform()
                    transform.SetMatrix(vtk_matrix)

                    translation_down = vtk.vtkTransform()
                    translation_down.Translate(0, -100, 0)

                    combined_transform = vtk.vtkTransform()
                    combined_transform.PostMultiply()
                    combined_transform.Concatenate(transform)
                    combined_transform.Concatenate(translation)
                    combined_transform.Concatenate(translation_down)

                    self.actor.SetUserTransform(combined_transform)

```
