# How rotate the axial slice in script to make it parallel with the plane across 3 specified points?

**URL:** <https://discourse.slicer.org/t/how-rotate-the-axial-slice-in-script-to-make-it-parallel-with-the-plane-across-3-specified-points/41187>\
**Category:** Support\
**Created:** [January 21, 2025, 9:37am UTC](https://discourse.slicer.org/t/how-rotate-the-axial-slice-in-script-to-make-it-parallel-with-the-plane-across-3-specified-points/41187 "2025-01-21T09:37:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SummerZ2020](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/summerz2020/32/7137_2.png) [@SummerZ2020](https://discourse.slicer.org/u/SummerZ2020)\
**Post date:** [January 21, 2025, 9:37am UTC](https://discourse.slicer.org/t/how-rotate-the-axial-slice-in-script-to-make-it-parallel-with-the-plane-across-3-specified-points/41187/1 "2025-01-21T09:37:53Z")

</div>

Operating system:windows  
Slicer version:5.6.2  
Expected behavior: After running script in slicer, the crossline in the slice window is rotated.  
Actual behavior: no any rotated happened.  
The script is:

```auto
# 
        markup_node = slicer.vtkMRMLMarkupsFiducialNode()
        markup_node.SetName("MyPoints")
        slicer.mrmlScene.AddNode(markup_node)

        # 
        print('le',points['le'])
        fiducial_index = markup_node.AddControlPoint(-1*points['le'][0][0], -1*points['le'][0][1], points['le'][0][2])
        markup_node.SetNthControlPointLabel(fiducial_index, 'le')
        fiducial_index = markup_node.AddControlPoint(-1*points['re'][0][0], -1*points['re'][0][1], points['re'][0][2])
        markup_node.SetNthControlPointLabel(fiducial_index, 're')
        fiducial_index = markup_node.AddControlPoint(-1*points['oo'][0][0], -1*points['oo'][0][1], points['oo'][0][2])
        markup_node.SetNthControlPointLabel(fiducial_index, 'oo')

        # 
        slicer.app.applicationLogic().GetSelectionNode().SetReferenceActivePlaceNodeID(markup_node.GetID())
        slicer.app.applicationLogic().PropagateVolumeSelection(0)

           #
        p0 = np.array(points['le'][0])
        p1 = np.array(points['re'][0])
        p2 = np.array(points['oo'][0])

        # 
        v1 = p1 - p0
        v2 = p2 - p0

        # 
        normal = np.cross(v1, v2)
        normal = normal / np.linalg.norm(normal) # 归一化

        # 
        #
        z_axis = normal
        x_axis = v1 / np.linalg.norm(v1)
        y_axis = np.cross(z_axis, x_axis)
        y_axis = y_axis / np.linalg.norm(y_axis)
        x_axis = np.cross(y_axis, z_axis)

        #
        transform_matrix = np.eye(4)
        transform_matrix[:3, 0] = x_axis
        transform_matrix[:3, 1] = y_axis
        transform_matrix[:3, 2] = z_axis
        transform_matrix[:3, 3] = p0

        # 
        print(f'Transform Matrix:\n{transform_matrix}')

        #
        slice_node = slicer.util.getNode('vtkMRMLSliceNodeRed')
        slice_node.GetSliceToRAS().DeepCopy(slicer.util.vtkMatrixFromArray(transform_matrix))
        slice_node.UpdateMatrices()

        # 
        slicer.app.applicationLogic().FitSliceToAll()

     
        print('Slice to RAS Transformed Matrix:')
        print(slice_node.GetSliceToRAS())

```

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [January 21, 2025, 10:00am UTC](https://discourse.slicer.org/t/how-rotate-the-axial-slice-in-script-to-make-it-parallel-with-the-plane-across-3-specified-points/41187/2 "2025-01-21T10:00:09Z")

</div>

You may get some insight [here](https://gitlab.com/chir-set/RcHacks7/-/blob/900664b75fca04210a065f1324d7fae0214eb559/12-ResliceToAxis.py.txt#L64) and [here](https://gitlab.com/chir-set/RcHacks7/-/blob/900664b75fca04210a065f1324d7fae0214eb559/00-Lib.py.txt#L125).

---

<div class="post-metadata">

**Author:** ![Antmaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/antmaker/32/81424_2.png) [@Antmaker](https://discourse.slicer.org/u/Antmaker)\
**Post date:** [February 21, 2026, 12:45am UTC](https://discourse.slicer.org/t/how-rotate-the-axial-slice-in-script-to-make-it-parallel-with-the-plane-across-3-specified-points/41187/3 "2026-02-21T00:45:50Z")

</div>

The GitLab repo is returning a 404. Could you provide another source or the code that was in the GitLab repo?
