我有一条线段定义为其起点和终点。
L = [(x1, y1), (x2, y2)]
所以
(x1, y1) (x2, y2)
L: A-------------------------------B
我现在想像这样拉开这两点来扩大界限
a a
L: A'--------A-------------------------------B-----------B'
所以我需要更新点A
和的坐标B
。
认为 A'A = B'B = a
如何在Python中完成?
这个问题可能是很相关的,但是我的问题主要集中在执行任务的算法上,而不是在图中将其形象化。
使用向量数学:
B = A + v
where
v = B - A = (x2-x1, y2-y1)
||v|| = sqrt((x2-x1)^2 + (y2-y1)^2)
The normalized vector v^ with ||v^|| = 1 is: v^ = v / ||v||
To get the values of A' and B' you can now use the direction
of v^ and the length of a:
B' = B + a * v^
A' = A - a * v^
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句