You can use IntersectWithLine function in VTK - see this post. There are many examples in the script repository to show how you can set up a locator.
You can do much more sophisticated analysis of the pedicle screw trajectory, for example analyze bone density traversed by the screw (not just a line but an actual screw shape), as it is done in Pedicle screw simulator extension.