如何在python中从另一条线的端点绘制一条垂直线?
我正尝试从给定长度的端点绘制与当前线段正交/垂直的线段,下面的插图有助于更好地解释问题:
I'm trying to draw a line segment orthogonal/perpendicular to the current line segment from the terminal point for a given length, here's an illustration to help better explain the problem:
给出 a线
坐标和任意 length
的坐标,我想找到线段 b
和的坐标(x3,y3)
.
Given the line a
coordinates and an arbitrary length
, I'd like to find the coordinates for line segment b
and (x3,y3)
.
感谢任何帮助.
更新:在此处找到了我的解决方案,并将其改编为Python,mod请将其标记为重复并关闭./p>
UPDATE: Found my solution here and adapted it to Python, mods please mark this as duplicate and close it.
我认为,使用sympy模块并获得它会很容易.
I think, it would be easy to use sympy module and get it.
import sympy.geometry as gm
line1=gm.Line(gm.Point(1,2),gm.Point(5,4))
line2=line1.perpendicular_line(line1.p2)
line1-是初始行(等式--2 x + 4 y-6)line2-是在端点(5,4)处绘制的垂直线(等式--4 x-2 y + 28)
line1 - is the initial line ( equation- -2x + 4y - 6) line2- is the perpendicular line drawn at the endpoint (5,4) (equation - -4x - 2y + 28)
请访问 https://docs.sympy.org/最新/模块/geometry/lines.html 详细了解线段.