# Slider rotation appears incorrect - vtkSliderRepresentation3D

**URL:** https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328
**Category:** Development
**Created:** [May 18, 2020, 5:02pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328 "2020-05-18T17:02:42Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jornskaa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jornskaa/32/1811_2.png) [@jornskaa](https://discourse.vtk.org/u/jornskaa)
#### Post date: [May 18, 2020, 5:02pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/1 "2020-05-18T17:02:42Z")

</div>

I have created a small test program that creates vtkSliderWidgets with the vtkSliderRepresentation3D. I create one slider per axis (not necessarily along the main coordinate system axes). Even though the three sliders have the same start point, one of the sliders seems to start offset from the start point and pointing slightly in the wrong direction.

sliderRep-\>SetPoint1InWorldCoordinates(0.0, 0.0, -6.0); // Note: All sliders have the same start point  
sliderRep-\>SetPoint2InWorldCoordinates(x, y, z);

The (x,y,z) coordinates for the axes are the following where the x-axis looks rotated incorrectly:

(0.8060793615028174, -4.596267436520017, -6.0)  
(-6.465520758172843, -1.1339033066529178, -6.0)  
(0.0, 0.0, 0.0)

vtkSliderRepresentation3D seems to want to rotate some geometry aligned along the x-axis with the slider axis defined by point1 and point2. Could there be an issue with the rotation calculation?

Also note that I have tried using vtkLineWidget instead of vtkSliderWidget and that seems to render the axes correctly with the correct start point and end point.

Got any ideas?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 18, 2020, 5:16pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/2 "2020-05-18T17:16:02Z")

</div>

Is the problem that sliders appear incorrectly or they don’t rotate objects as you expect? Can you post a screenshot?

---

<div class="post-metadata">

### Author: ![jornskaa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jornskaa/32/1811_2.png) [@jornskaa](https://discourse.vtk.org/u/jornskaa)
#### Post date: [May 18, 2020, 5:22pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/3 "2020-05-18T17:22:34Z")

</div>

Here is a screenshot of the sliders - one for each axis and you will see one which does not have the same start point as the others.

 ![slider_issue](https://discourse.vtk.org/uploads/default/original/2X/8/84afe33df2795cfc55c8f34effd934780002af61.png)

Here is my test with vtkLineWidget with the same coordinates - it appears to render as expected.

 ![vtkLineWidget](https://discourse.vtk.org/uploads/default/original/2X/f/f88a7fb3ac7e132208f80abad73d7dfcbd5bb40b.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 18, 2020, 5:54pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/4 "2020-05-18T17:54:18Z")

</div>

Not the same starting point is a minor issue compared to the text being distorted and mirrored. You would normally use these sliders in a 2D renderer layer that does not move/rotate with your 3D scene content.

---

<div class="post-metadata">

### Author: ![jornskaa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jornskaa/32/1811_2.png) [@jornskaa](https://discourse.vtk.org/u/jornskaa)
#### Post date: [May 18, 2020, 6:12pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/5 "2020-05-18T18:12:24Z")

</div>

My application does use sliders a part of a scene that can be rotated. Seems this could be a normal use case scenario? Currently used for moving slices inside a volume dataset.

The start point is incorrect, but so is probably the end point since the rotation used is probably not what it should be (guess maybe the middle point could be correct though 🙂 ) .

I do believe correctness should be important when it comes to positioning though also agree that text should be readable preferably from any rotation. Think the position issue could easily be fixed?

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [May 19, 2020, 12:48pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/6 "2020-05-19T12:48:15Z")

</div>

> My application does use sliders a part of a scene that can be rotated. Seems this could be a normal use case scenario? Currently used for moving slices inside a volume dataset.

I recently implemented something very similar but I dont get the problem with the widgets orientation:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/140fefff7aaa1598ab3f437548567e49dfa72e97.png)

you can check out how it’s done [here](https://github.com/marcomusy/vtkplotter/blob/master/vtkplotter/examples/advanced/slicer.py), [here](https://github.com/marcomusy/vtkplotter/blob/e51e869972ce0c329c33c824a503ca6db7ca5f1d/vtkplotter/applications.py#L20) and [here](https://github.com/marcomusy/vtkplotter/blob/e51e869972ce0c329c33c824a503ca6db7ca5f1d/vtkplotter/addons.py#L470).

---

<div class="post-metadata">

### Author: ![jornskaa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jornskaa/32/1811_2.png) [@jornskaa](https://discourse.vtk.org/u/jornskaa)
#### Post date: [May 20, 2020, 9:27am UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/7 "2020-05-20T09:27:15Z")

</div>

Would it be possible for you to test with the coordinates provided above and see if the sliders appear correct for you?

point1: (0.0, 0.0, -6.0)  
point2:  
(0.8060793615028174, -4.596267436520017, -6.0) -\> this should appear incorrect  
(-6.465520758172843, -1.1339033066529178, -6.0)  
(0.0, 0.0, 0.0)

I have also pushed my test code to a repo if you would like to try there.

[https://bitbucket.org/jornskaa/vtksliderwidget/](https://bitbucket.org/jornskaa/vtksliderwidget/)

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [May 20, 2020, 12:50pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/8 "2020-05-20T12:50:39Z")

</div>

is it that maybe point1 and point2 are swapped wrt the linewidget case?

```auto
  sliderRep->SetPoint1InWorldCoordinates(x+0.5, y, z);
  sliderRep->SetPoint2InWorldCoordinates(0,0,0);
//...
  auto sliderWidgetX = createSliderWidget(30, renderWindowInteractor, 1, 0, 0);
  auto sliderWidgetY = createSliderWidget(30, renderWindowInteractor, 0, 1, 0);
  auto sliderWidgetZ = createSliderWidget(30, renderWindowInteractor, 0, 0, 1);

```

![image](https://discourse.vtk.org/uploads/default/original/2X/d/d2623fbbd4f636d81545ab4a4af14246a726f15a.png)

---

<div class="post-metadata">

### Author: ![jornskaa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jornskaa/32/1811_2.png) [@jornskaa](https://discourse.vtk.org/u/jornskaa)
#### Post date: [May 25, 2020, 12:39pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/9 "2020-05-25T12:39:07Z")

</div>

I have tried swapping the coordinates as well, but the situation is still the same/similar. Have you tried to use the coordinates I provided? Would be interesting if you can reproduce the situation. In your post you use the main coordinate axes which I think should work fine for me as well.

---

<div class="post-metadata">

### Author: ![jornskaa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jornskaa/32/1811_2.png) [@jornskaa](https://discourse.vtk.org/u/jornskaa)
#### Post date: [June 8, 2020, 12:15pm UTC](https://discourse.vtk.org/t/slider-rotation-appears-incorrect-vtksliderrepresentation3d/3328/10 "2020-06-08T12:15:41Z")

</div>

I have found vtkSliderRepresentation3D::BuildRepresentation to calculate an incorrect angle of rotation of the slider mesh in some cases. I have tried correcting this by replacing:

```
vtkMath::Normalize(v);
vtkMath::Cross(v,x,axis);
double theta, axisLen = vtkMath::Norm(axis);
if ( axisLen != 0.0 )
{
  theta = vtkMath::DegreesFromRadians( asin( axisLen ) );
}

```

With this:

```
vtkMath::Normalize(v);
vtkMath::Cross(v,x,axis);
double dotProd = vtkMath::Dot(v, x);
double theta, axisLen = vtkMath::Norm(axis);
if ( axisLen != 0.0 )
{
  theta = vtkMath::DegreesFromRadians(vtkMath::Pi() - atan2(axisLen, dotProd));
}

```

Basically a directional angle is found instead of the one found by asin, and that seems to work for my case. Haven’t tested this a lot yet, but seems to work for me right now. Hopefully a similar fix can be made to VTK as well 🙂
