# When I use vtkLineWidget2, when it rotates, its handle does not follow its rotation

**URL:** https://discourse.vtk.org/t/when-i-use-vtklinewidget2-when-it-rotates-its-handle-does-not-follow-its-rotation/15032
**Category:** Support
**Created:** [December 17, 2024, 2:32am UTC](https://discourse.vtk.org/t/when-i-use-vtklinewidget2-when-it-rotates-its-handle-does-not-follow-its-rotation/15032 "2024-12-17T02:32:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 17, 2024, 2:32am UTC](https://discourse.vtk.org/t/when-i-use-vtklinewidget2-when-it-rotates-its-handle-does-not-follow-its-rotation/15032/1 "2024-12-17T02:32:21Z")

</div>

When I use vtkLineWidget2, when it rotates, its handle does not follow its rotation

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 17, 2024, 2:34am UTC](https://discourse.vtk.org/t/when-i-use-vtklinewidget2-when-it-rotates-its-handle-does-not-follow-its-rotation/15032/2 "2024-12-17T02:34:14Z")

</div>



---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [December 17, 2024, 2:38am UTC](https://discourse.vtk.org/t/when-i-use-vtklinewidget2-when-it-rotates-its-handle-does-not-follow-its-rotation/15032/3 "2024-12-17T02:38:43Z")

</div>

This is the core code：  
{ vtkNew line;

```
    line->SetInteractor(Interactor);
    line->SetCurrentRenderer(renderer);
    //mLine->SetPlaceFactor(1.0); 
    line->SetEnabled(1);
  
    
    vtkNew<vtkLineRepresentation> lineRep;
    lineRep->SetPoint1WorldPosition(picked);
    lineRep->SetPlaceFactor(1.0);

    vtkNew<vtkActorCollection> actors;
    lineRep->GetActors(actors);
    lineRep->SetLineColor(0, 1, 0);
    actors->InitTraversal();

    vtkNew<vtkTransform> transform;
     mLine2TransformMap[line.Get()] = transform.Get();
    while (vtkActor* actor = actors->GetNextActor())
    {
        actor->SetUserTransform(transform);
    }

    line->SetRepresentation(lineRep);
    line->On();

```

}  
void CustomVtkInteractorStyleRuler::Rotate() {  
if (!mPicked) {  
CustomVtkInteractorStyleCtrlModel::Rotate();  
int dx = this-\>Interactor-\>GetEventPosition()[0] - this-\>Interactor-\>GetLastEventPosition()[0];  
int dy = this-\>Interactor-\>GetEventPosition()[1] - this-\>Interactor-\>GetLastEventPosition()[1];

```
    double angleX = dx * 0.5; // Adjust sensitivity
    double angleY = dy * 0.5;
    for (auto kvp : mLine2TransformMap)
    {
        vtkTransform* transform = kvp.second;
        transform->PostMultiply();
        transform->RotateY(angleX);
        transform->RotateX(-angleY);
    }

}
else
{
    ......
}

```

}

---

<div class="post-metadata">

### Author: ![jiajiadelequ](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jiajiadelequ/32/8738_2.png) [@jiajiadelequ](https://discourse.vtk.org/u/jiajiadelequ)
#### Post date: [January 13, 2025, 5:25am UTC](https://discourse.vtk.org/t/when-i-use-vtklinewidget2-when-it-rotates-its-handle-does-not-follow-its-rotation/15032/4 "2025-01-13T05:25:36Z")

</div>

Can anyone help me analyze why the handle position of lineWidget does not rotate after rotation
