python - 如何根据四个端点获得四个坐标
问题描述
假设在图中我有四个角的四个端点
C1(0,0) C2(0,9) C3(9,9) C4(9,0).
当目标位于四个端点中间的某个位置时,是否可以获得四个坐标(与四个端点的距离)。
就像我将目标放在:
(7,1) 相对于 C1 端点。
补充说我应该得到:(2,1)来自C4,同样来自C2和C3。
解决方案
像这样:
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)
推荐阅读
- python - 检查每个字母
- uwp - 为什么 Header 比 Title 大,什么时候使用?
- vulkan - Vulkan 队列提交同步 - vkWaitForFences vs vkQueueWaitIdle
- javascript - 无法在基于反应的应用程序上单击带有 selenium webdriver 的按钮
- python - session.add() 和会话方法不存在
- ios - SwiftUI:我想每天显示一个随机元素,即使在重新启动应用程序之后也是如此
- typescript - 类型“{}”上不存在属性“onMessage”。& “{}”类型的参数不能分配给“null”类型的参数
- mysql - 如果 Id,如何获取名称
- python - 计算列表列表中的词频
- r - R(或Rcpp)中的并行稀疏矩阵rowSums