线段python的圆上最近的点 [英] Closest point on a circle to a line segment python

查看:156
本文介绍了线段python的圆上最近的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出盒子和圆圈之间的最近距离,但是,我意识到这可以分解为线段和圆圈之间的最近距离。

I need to find the closest distance between a box and a circle, however, I realize this can be broken up into the closest distance between a line segment and a circle.


  • 我有线段 point1_x point1_y point2_x point2_y

  • 我有一个圆圈,中心 circle_x circle_y radius radius

  • I have a line segment of two points point1_x,point1_y and point2_x, point2_y
  • I have a circle with center circle_x, circle_y and radius radius

是否有一个python库支持这个开箱即用的功能,如果不是,有人可以提供一个函数来完成所以?

Is there a python library that will support this out of the box and if not can somebody present a function to do so?

(我相信我必须找到与该线相同斜率的圆上的切点?)

(I belive I have to locate the tangent point on the circle with the same slope as the line?)

推荐答案

模块。安装时使用:

The euclid module. Install with:

pip install euclid

然后像这样使用它:

Then use it like this:

>>> from euclid import *

>>> circ = Circle(Point2(3., 2.), 2.)
>>> line = Line2(Point2(0., 0.), Point2(-1., 1.))
>>> line.distance(circ)
1.5355339059327378

这篇关于线段python的圆上最近的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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