Here is the code to reproduce the bug:
import numpy as np
lineNode = slicer.mrmlScene.CreateNodeByClass("vtkMRMLMarkupsLineNode")
lineNode.SetName("screwLine")
slicer.mrmlScene.AddNode(lineNode)
#display node of the plane
displayNode = lineNode.GetDisplayNode()
displayNode.UseGlyphScaleOff()
displayNode.SetGlyphSize(8)
displayNode.SetOpacity(1)
displayNode.SetLineThickness(0)
lineNode.AddControlPoint(vtk.vtkVector3d(45.0,11.0,0.0))
lineNode.AddControlPoint(vtk.vtkVector3d(-26.0,-10.0,0.0))
def moveLineOnLineDirection():
lineStartPoint = np.array([0,0,0])
lineEndPoint = np.array([0,0,0])
lineNode.GetNthControlPointPosition(0,lineStartPoint)
lineNode.GetNthControlPointPosition(1,lineEndPoint)
lineDirection = (lineEndPoint - lineStartPoint)/np.linalg.norm(lineEndPoint - lineStartPoint)
stepmm = 5
stepDirection = lineDirection
lineTranslationTransform = vtk.vtkTransform()
lineTranslationTransform.PostMultiply()
lineTranslationTransform.Translate(stepmm*stepDirection)
lineTranslationTransformNode = slicer.vtkMRMLLinearTransformNode()
lineTranslationTransformNode.SetName("lineTranslationTransform")
slicer.mrmlScene.AddNode(lineTranslationTransformNode)
lineTranslationTransformNode = slicer.vtkMRMLLinearTransformNode()
lineTranslationTransformNode.SetName("screwToScrewLineTransform")
slicer.mrmlScene.AddNode(lineTranslationTransformNode)
lineTranslationTransformNode.SetMatrixTransformToParent(
lineTranslationTransform.GetMatrix())
lineNode.SetAndObserveTransformNodeID(lineTranslationTransformNode.GetID())
lineNode.HardenTransform()
slicer.mrmlScene.RemoveNode(lineTranslationTransformNode)
translatedLineStartPoint = np.array([0,0,0])
translatedLineEndPoint = np.array([0,0,0])
lineNode.GetNthControlPointPosition(0,translatedLineStartPoint)
lineNode.GetNthControlPointPosition(1,translatedLineEndPoint)
translatedLineDirection = (translatedLineEndPoint - translatedLineStartPoint)/np.linalg.norm(translatedLineEndPoint - translatedLineStartPoint)
cosOfAngle = vtk.vtkMath.Dot(lineDirection,translatedLineDirection)
import math
angleDifference = math.degrees(math.acos(cosOfAngle))
print(angleDifference)
moveLineOnLineDirection()
Open Slicer, open the python interactor, paste the code, see that the printed angle difference is near 1degree and it should be zero, (optional, move the line control points, execute moveLineOnLineDirection again and see the angle difference result: it’s not always zero)