我有一个要点列表,想确定它们是否形成一个圆 [英] I have a list of points and would like to determine if they form a circle

查看:92
本文介绍了我有一个要点列表,想确定它们是否形成一个圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#,我有一个Vector点列表,想尝试估算它们看起来像一个圆的接近程度.

I'm using C#, I have a list of Vector points and would like to try and approximate how close they look like a circle.

有什么想法可以实现这一目标吗?或者其他人有吗?

Any ideas how to implement this or if someone else has?

推荐答案

1)从该列表中选择任意三个点,找到其相应圆的中心

1) Pick any three points from that list, find the center of their appropriate circle

我们可以这样做,使用三角形外接圆构建方法,您可以找到所有三个边的中位数(两个就足够了),并且它们的交点是圆的中心.像这样:

We can do this, using triangle circumcircle construction method, you find the medians of all three sides (two are sufficient) and their intersection is the center of the circle. Something like this:

public PointF findCenter(PointF a, PointF b, PointF c)
{
    float k1 = (a.Y - b.Y) / (a.X - b.X) //Two-point slope equation
    float k2 = (a.Y - c.Y) / (a.X - c.X) //Same for the (A,C) pair
    PointF midAB = new PointF((a.X + b.X) / 2, (a.Y + b.Y) / 2) //Midpoint formula
    PointF midAC = new PointF((a.X + c.X) / 2, (a.Y + c.Y) / 2) //Same for the (A,C) pair
    k1 = -1*k1; //If two lines are perpendicular, then the product of their slopes is -1.
    k2 = -1*k2; //Same for the other slope
    float n1 = midAB.Y - k1*midAB.X; //Determining the n element
    float n2 = midAC.Y - k2*midAC.Y; //Same for (A,C) pair
    //Solve y1=y2 for y1=k1*x1 + n1 and y2=k2*x2 + n2
    float x = (n2-n1) / (k1-k2);
    float y = k1*x + n1;
    return new PointF(x,y);
}

2)检查其他点与该中心的距离是否相等,如果是,则有一个圆,否则,则没有.

2) Check if the other points are equivalently distanced from this center, if yes, you have a circle, if no, you don't.

P.S.我尚未测试代码,因此请准备调试.询问您是否还需要其他东西

P.S. I haven't tested the code, so be prepared to debug. Ask if you need anything else

这篇关于我有一个要点列表,想确定它们是否形成一个圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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