Hello!
Using the pyransac3d algorithm, I calculate the cylinder parameters and then try to create an actor from them. I know that the parameters such as the normal determine well, as for example the height of the cylinder is correct according to the normal as well as the points selected for best fitting, However, my cylinder is still not rotated in the right direction. Why? What am I doing wrong in the code?
def draw_cylinder(
self, radius: float = 1.0, height: float = 5.0,
center: tuple[float, float, float] = (0.0, 0.0, 0.0),
normal: tuple[float, float, float] = (0.0, 0.0, 1.0),
color: tuple[float, float, float] = (1.0, 1.0, 1.0), opacity: float = 1.0,
res: float = 100) -> vtkActor:
"""Create and add cylinder actor for scene.
:param center: Center of the cylinder.
:type center: tuple[float, float, float]
:param normal: Normal to the cylinder.
:type normal: tuple[float, float, float]
:param radius: Radius of the cylinder.
:type radius: float
:param height: Height of the cylinder.
:type height: float
:param color: Color of the cylinder actor.
:type color: tuple[float, float, float]
:param opacity: Opacity of the cylinder actor.
:type opacity: float
:param res: Resolution of the cylinder actor.
:type res: float
:return: Return created actor.
:rtype: vtkActor
"""
cylinder = vtkCylinderSource()
cylinder.SetRadius(radius)
cylinder.SetHeight(height)
cylinder.SetResolution(res)
transform = vtkTransform()
transform.Translate(center) # Set the position
# Set the orientation based on the normal
# You may need to adjust this depending on your coordinate system
transform.RotateWXYZ(90, normal[0], normal[1], normal[2])
# Apply the transformation to the actor
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(cylinder.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(*color)
actor.GetProperty().SetOpacity(opacity)
actor.SetUserTransform(transform)
self.add_actor(actor)
return actor