根据距A点的距离在线找到B点 [英] Find point-B on line by distance from point-A

查看:68
本文介绍了根据距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点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆