# Extract local Coordinates from a line and plane in a coordinate model

**URL:** <https://discourse.slicer.org/t/extract-local-coordinates-from-a-line-and-plane-in-a-coordinate-model/28268>\
**Category:** Support\
**Tags:** python\
**Created:** [March 10, 2023, 1:17am UTC](https://discourse.slicer.org/t/extract-local-coordinates-from-a-line-and-plane-in-a-coordinate-model/28268 "2023-03-10T01:17:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MAURICIO\_ALBERTO\_LED](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mauricio_alberto_led/32/12480_2.png) [@MAURICIO\_ALBERTO\_LED](https://discourse.slicer.org/u/MAURICIO_ALBERTO_LED)\
**Post date:** [March 10, 2023, 1:17am UTC](https://discourse.slicer.org/t/extract-local-coordinates-from-a-line-and-plane-in-a-coordinate-model/28268/1 "2023-03-10T01:17:54Z")

</div>

Operating system: win 11  
Slicer version:5.0.2

I need to calculate the local coordinates of a Line and a Plane, in a new coordinate system.

 ![Captura de pantalla 2023-03-09 201659](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/9/b9cc5b5c73c1567de82fad1ce8d12f6a3d09730f.jpeg)

When I execute this code I can retrieve the coordinates in a world coordinate system. But I need the local coordinates of the L\_1 (blue line) Line with respect to the yellow coordinate system. Thanks for the help.

import multiprocessing as mp  
import numpy as np # import library

lineNodeNames = [“L\_1”]

lineNode = slicer.util.getFirstNodeByClassByName(“vtkMRMLMarkupsLineNode”, lineNodeNames[0]) # Return the first node in the scene that matches the specified node class(“vtkMRMLMarkupsLineNode” in this case ) and node name(ech plane "lineNodeName " in the list lineNodeNames ) .  
print(“lineNode:”, lineNode)  
lineStartPos = np.zeros(3) # Return a new array of given shape and type, filled with “3” zeros and saves in lineStartPos  
print(“lineStartPos:”, lineStartPos)  
lineEndPos = np.zeros(3) # Return a new array of given shape and type, filled with “3” zeros and saves in lineEndPos  
print(“lineEndPos:”, lineEndPos)  
lineNode.GetNthControlPointPositionWorld(0, lineStartPos) # Get the position of the Nth control point in World coordinate system Returns 0 on failure, 1 on success.  
print(“lineNode \_ 0:”, lineStartPos)  
lineNode.GetNthControlPointPositionWorld(1, lineEndPos) # Get the position of the Nth control point in World coordinate system Returns 0 on failure, 1 on success.

print(“lineNode \_ 1:”, lineEndPos)

---

<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:** [March 10, 2023, 6:21pm UTC](https://discourse.slicer.org/t/extract-local-coordinates-from-a-line-and-plane-in-a-coordinate-model/28268/2 "2023-03-10T18:21:03Z")

</div>

If you know the world coordinates of the desired origin (yellow intersection), the first idea that comes to mind is to subtract this yellow origin from lineStartPos and lineEndPos. Does this fit your requirements? It could be I didn’t fully understand the problem.
