Home > database >  Sympy: How to calculate the t value for a point on a 3D Line
Sympy: How to calculate the t value for a point on a 3D Line

Time:04-05

Using sympy how would one go about to solve for the t value for a specific point on a line or line segment?

p1 = sympy.Point3D(0,0,0)
p2 = sympy.Point3D(1,1,1)
p3 = sympy.Point3D(0.5,0.5,0.5)
lineSegment = sympy.Segment(p1,p2)
eqnV = lineSegment.arbitrary_point()

if lineSegment.contains(p3):
    t = SolveForT(lineSegment, p3) 

CodePudding user response:

You can get a list of coordinate equations and pass them to sympy's solve function:

In [112]: solve((lineSegment.arbitrary_point() - p3).coordinates)
Out[112]: {t: 1/2}
  • Related