# Mirroring a rotation around the axis for a transform node

**URL:** <https://discourse.slicer.org/t/mirroring-a-rotation-around-the-axis-for-a-transform-node/10997>\
**Category:** Development\
**Tags:** transforms, slicerrt\
**Created:** [April 5, 2020, 5:44am UTC](https://discourse.slicer.org/t/mirroring-a-rotation-around-the-axis-for-a-transform-node/10997 "2020-04-05T05:44:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [April 5, 2020, 5:44am UTC](https://discourse.slicer.org/t/mirroring-a-rotation-around-the-axis-for-a-transform-node/10997/1 "2020-04-05T05:44:02Z")

</div>

Is it possible to mirror a rotation around the axis in a simple way (not making negative specific elements of the matrix) for a transform node?

For example the code:

`vtkMRMLLinearTransformNode* gantryToFixedReferenceTransformNode =`  
` this->GetTransformNodeBetween(Gantry, FixedReference);`  
` vtkTransform* gantryToFixedReferenceTransform = vtkTransform::SafeDownCast(gantryToFixedReferenceTransformNode->GetTransformToParent());`  
` gantryToFixedReferenceTransform->Identity();`  
` gantryToFixedReferenceTransform->RotateY(beamNode->GetGantryAngle());`  
` gantryToFixedReferenceTransform->Modified();`  
`... some other code ...`  
` gantryToFixedReferenceTransform->MirrorY(); // mirror the rotation`  
`gantryToFixedReferenceTransform->Modified();`

Without mirror (not very good):

 ![Screenshot_2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/1/21e8f71e9a416d17ce128798e929390517a7fe75.png)

With mirror (much better):

 ![Screenshot_3](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/9/d9b86c815d3390189297c2b3cca6cb9d3ad261ca.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 5, 2020, 5:15pm UTC](https://discourse.slicer.org/t/mirroring-a-rotation-around-the-axis-for-a-transform-node/10997/2 "2020-04-05T17:15:45Z")

</div>

> [@Mik](#):
>
> Is it possible to mirror a rotation around the axis in a simple way (not making negative specific elements of the matrix) for a transform node?

You can mirror by calling `vtkTransform::Scale`. Use `-1` as scale factor for the axes you want to mirror around and `1` for other axes. Note that for moving physical objects it should not be ever necessary to mirror (as you cannot mirror physical objects in real life either), but you can achieve all physically possible displacements by translate and rotate methods.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)\
**Post date:** [April 5, 2020, 6:11pm UTC](https://discourse.slicer.org/t/mirroring-a-rotation-around-the-axis-for-a-transform-node/10997/3 "2020-04-05T18:11:53Z")

</div>

It’s safer use rotation on a negative angle for a simple task, i think.

`transform->Identity();`  
`transform->RotateY(angle);`  
`transform->Modified();`  
`... some other code ...`  
`transform->Identity(); `  
`transform->RotateY(-1. * angle); // mirror the rotation `  
` transform->Modified();`
