线和圆的交点 [英] line and circle intersection

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

问题描述

可能重复:
具有不同斜率的直线和圆的交集

Possible Duplicate:
intersection of line and circle with different slope

我有由pp=randi([-400 400],2,2)然后由x=pp(:,1)y=pp(:,2)绘制的线.我有一个中心为(a,b)且半径为r的圆

I have line which plotted by pp=randi([-400 400],2,2) then x=pp(:,1) and y=pp(:,2). I have a circle with centre (a,b) with radius r

我想检查圆与线的交点.

I want to check the intersection point of circle and the line.

我已经使用polyfit命令来检查坡度和截距.然后,我使用了lincirc命令,但问题是,如果该线仅跨越一个点,那么还将显示另一点.

I have used polyfit command to check the slope and intercept. Then I used lincirc command but the problem is if the line crosses only one point then the other point is also shown.

例如,如果线越过一侧并在中间停止,则它也将显示另一条不会越过边界的点

For example, if the line crosses one side and stops in the middle, it shows the other point as well which will not cross the boundary

推荐答案

您有一个以(a,b)为中心的圆半径r.你有条线.如果已绘制这些点,则必须将数据存储在x和y向量中,因此,将元素的第一个和最后一个作为(x,y)坐标.第一对形成线的起点,最后一对形成终点.将这些点称为(c1,d1)和(c2,d2).假设您的lincirc函数告诉您线与圆之间有2个交点,请计算

You have a circle radius r centred at (a,b). You have a line. If you have plotted these points, you must have your data stored in x and y vectors, so you take the first and last of elements each as (x,y) coordinates. The first pair form the line start point and last pair the end point. Refer to these points as (c1,d1) and (c2,d2). Assuming that your lincirc function tells you there are 2 intersection points between line and circle, calculate

A1 = (c1-a,d1-b)
A2 = (c2-a,d2-b)

现在,如果

norm(A1,2) < r

然后端点(c1,d1)在您的圈子内,如果

then endpoint (c1,d1) is inside your circle, if

norm(A2,2) < r

然后端点(c2,d2)在圆内.

then endpoint (c2,d2) is inside your circle.

如果其中一个点在圆内,则您只有一个相交点.

If one of the points is inside the circle, then you only have one intersection point.

如果两个点都不在圆内,则您知道直线越过圆两次(假设lincirc函数告诉您有2个点)

If neither point is inside the circle, then you know that your line crosses the circle twice (assuming that your lincirc function tells you there are 2 points)

如果两个点都在圆内,则您的lincirc函数对您说谎.

If both points are inside the circle, then your lincirc function is lying to you.

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

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