我需要一个公式来计算第三个点的位置,因为我们知道Point1和Point2的位置和线的长度(Point1,Point2)和线的长度(Point1,Point3)。

# We represent it as follows:
Point1 as P1, Point2 as P2, Point3 as P3
P1 = (2, 16) or P1x,P1y = (2, 16)
P2 = (8, 10) or P2x,P2y = (8, 10)
length of the line (P1, P2) as L1, Length of the line (P1, P3) as L2
# I want to make length of the L2 longer than L1 ( so I plus 5 to length of the line L1 )
L1 = 8.5
L2 = L1 + 5 = 13.5
Find : Point 3 => P3 = (P3x = ?, P3y =?)这是我的代码:如何找到这一行的长度。
import math
def calculateDistance(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist那么我们如何才能找到P3的位置呢?
Find : P3 = (P3x = ?, P3y =?)发布于 2022-01-02 10:34:41
向量P1->P3和P1->P2是共线的,说明P1->P3的坐标与P1->P2的坐标成正比,比例因子必须是长度length(P1->P3) / length(P1->P2)的比值。
这为P3x和P3y提供了一个等式:
P3x - P1x == (L2 / L1) * (P2x - P1x)
P3y - P1y == (L2 / L1) * (P2y - P1y)将其转化为P3x和P3y的定义:
ratio = L2 / L2
P3x = P1x + ratio * (P2x - P1x)
P3y = P1y + ratio * (P2y - P1y)注意,您不需要定义自己的distance函数;标准库math模块中已经有一个:https://docs.python.org/3/library/math.html#math.dist
from math import dist
print( dist((2,16), (8,10)) )
# 8.485281374238571https://stackoverflow.com/questions/70554714
复制相似问题