根据距A点的距离在线找到B点

编程入门 行业动态 更新时间:2024-10-24 06:38:44
本文介绍了根据距A点的距离在线找到B点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有线方程,点A和距离,并且需要在距离的边缘找到点B.我有2个方程:

I have line-equation, point-A and distance, and need to find point-B at the edge of the distance, on the line. I have 2 equations:

distance = math.sqrt((pt1[0] - pt2[0])**2 + (pt1[1] - pt2[1])**2) pt2[1] = m*pt2[0] + n

距离,pt1,m和n是已知的.

distance, pt1, m and n are known.

如何在Python中实现此计算?也许有一个Python库可以为我做到这一点?

How can I implement this calculation in Python? Maybe there is a Python library that can do this for me?

推荐答案

给出线 y = mx + b ,斜率 m 告诉我们变化之间的比率在x( dx )中显示,在y( dy )中变化.

Given the line y=mx+b, the slope m tells us the ratio between the change in x (dx) and the change in y (dy).

数学:

// Given point_b = (point_a[0]+dx,point_a[1]+dy) other_possible_point_b = (point_a[0]-dx,point_a[1]-dy) dy = m*dx x**2 + y**2 = distance // Calculations dx**2 + (m*dx)**2 = distance (m**2+1)(dx**2) = distance dx = sqrt(distance/(m**2+1)) dy = m*sqrt(distance/(m**2+1))

Python解决方案:

Python solution:

from math import sqrt point_b = (point_a[0]+dx(distance,m), point_a[1]+dy(distance,m)) other_possible_point_b = (point_a[0]-dx(distance,m), point_a[1]-dy(distance,m)) # going the other way def dy(distance, m): return m*dx(distance, m) def dx(distance, m): return sqrt(distance/(m**2+1))

更多推荐

根据距A点的距离在线找到B点

本文发布于:2023-07-27 23:13:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1225209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   距离

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!