For example, I have a cylinder, whose center point is (0, 10, 0)
. I want this cylinder can rotation 30 degree along x axis with (0, 10, 0)
as the rotation center. My code is:
import vtkmodules.all as vtk
cylinder = vtk.vtkCylinderSource()
cylinder.SetCenter(0, 10, 0)
cylinder.SetRadius(5)
cylinder.SetHeight(10)
cylinder.SetResolution(100)
cylinder.Update()
cylinderMapper = vtk.vtkPolyDataMapper()
cylinderMapper.SetInputData(cylinder.GetOutput())
cylinderActor = vtk.vtkActor()
cylinderActor.SetMapper(cylinderMapper)
cylinderActor.GetProperty().SetOpacity(0.3)
########################################################
# rotation
transform = vtk.vtkTransform()
transform.RotateX(30)
cylinderActor.SetUserTransform(transform)
########################################################
def Line(p0, p1, c):
line = vtk.vtkLineSource()
line.SetPoint1(p0[0], p0[1], p0[2])
line.SetPoint2(p1[0], p1[1], p1[2])
line.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(line.GetOutput())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(c[0], c[1], c[2])
return actor
x = Line(p0=[0, 0, 0], p1=[20, 0, 0], c=[1, 0, 0])
y = Line(p0=[0, 0, 0], p1=[0, 20, 0], c=[0, 1, 0])
z = Line(p0=[0, 0, 0], p1=[0, 0, 20], c=[0, 0, 1])
renderer = vtk.vtkRenderer()
renderer.AddActor(cylinderActor)
renderer.AddActor(x)
renderer.AddActor(y)
renderer.AddActor(z)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.Initialize()
iren.Start()
The final result is:
We can see that the rotation center point is (0, 0, 0)
. How can I set the rotation center point to (0, 10, 0)
. I hope I can ahieve the following picture:
The above figure is obtained using vtk3DProp::SetOrigin
& vtk3DProp::RotateX
. How can I achieve the same result using vtkTransform
and SetUserTransform
.
Ang suggestion is appreciated~~~