首页 > 解决方案 > 如何根据四个端点获得四个坐标

问题描述

假设在图中我有四个角的四个端点

C1(0,0) C2(0,9) C3(9,9) C4(9,0).

当目标位于四个端点中间的某个位置时,是否可以获得四个坐标(与四个端点的距离)。

就像我将目标放在:

(7,1) 相对于 C1 端点。

补充说我应该得到:(2,1)来自C4,同样来自C2和C3。

插图

标签: pythonexcelmathgraph

解决方案


像这样:

C1 = (0,0)
C2 = (0,9)
C3 = (9,9)
C4 = (9,0)

T = (7,1)

T_C1 = (abs(T[0]-C1[0]),abs(T[1]-C1[1])) # Finding to difference between the x,y coordinates of T (target) and C1
T_C2 = (abs(T[0]-C2[0]),abs(T[1]-C2[1])) # Finding to difference between the x,y coordinates of T (target) and C2
T_C3 = (abs(T[0]-C3[0]),abs(T[1]-C3[1])) # Finding to difference between the x,y coordinates of T (target) and C3
T_C4 = (abs(T[0]-C4[0]),abs(T[1]-C4[1])) # Finding to difference between the x,y coordinates of T (target) and C4

print(T_C1,T_C2,T_C3,T_C4)

输出:

(7, 1) (7, -8) (-2, -8) (-2, 1)

推荐阅读