如何在三维空间中给定三个点找到圆的半径C#

3
我知道三个点在圆上的位置,分别是 pt1(x1, y1,z1)pt2(x2, y2, z2)pt3(x3, y3,z3)。我需要找到这个圆的半径。已经有一个用于计算二维空间半径的函数,现在将其复制在这里。
public static double ComputeRadius(Location a, Location b, Location c)
        {
            double x1 = a.x;
            double y1 = a.y;
            double x2 = b.x;
            double y2 = b.y;
            double x3 = c.x;
            double y3 = c.y;
            double mr = (double)((y2 - y1) / (x2 - x1));
            double mt = (double)((y3 - y2) / (x3 - x2));

            double xc = (double)((mr * mt * (y3 - y1) + mr * (x2 + x3) - mt * (x1 + x2)) / (2 * (mr - mt)));

            double yc = (double)((-1 / mr) * (xc - (x1 + x2) / 2) + (y1 + y2) / 2);
            double d = (xc - x1) * (xc - x1) + (yc - y1) * (yc - y1);

            return Math.Sqrt(d);
        }

这与数学有关,与编程无关。编程方面:仅涉及一些数字操作。数学方面:请在数学上提出问题。 - M.kazem Akhgary
我们不知道4个点的情况下,就无法计算半径吗? - Mohamed Sirajudeen
@MohamedSirajudeen:抱歉 - 我看成了“球体”而不是“圆形”。三个点完全没问题。 - joe
我不是100%确定,因此在评论而不是回答,但是如果我们取这些3D点形成的三角形的边长(这将涉及执行sqrt(pow(x1-x2,2) + pow(y1-y2,2) + pow(z1-z2,2))等操作),如果我们将这些长度命名为lalblc,则找到半径的公式将是:2*la*lb*lc / sqrt((la+lb+lc)*(lb+lc-la)*(la+lc-lb)*(la+lb-lc)) - Jcl
请参见此处的示例:http://mathematica.stackexchange.com/questions/16209/how-to-determine-the-center-and-radius-of-a-circle-given-some-points-in-3d - M.kazem Akhgary
1个回答

2

如果您知道圆上点 pt1,pt2,pt3 的顺序,那么可以使用图形方法:

  1. cast normal axises from middle of each line segment in the plane of circle

    your circle plane is defined by your 3 points. so the normal vector is

    n = (pt2-pt1) x (pt3-pt2)
    

    where the x is cross product so you have 2 lines (pt1,pt2) and (pt2,pt3) in black. The mid points are easy

    p0=0.5*(pt1+pt2)
    p1=0.5*(pt2+pt3)
    

    the axis directions can be obtained also by cross product

    dp0=(pt2-pt1) x n
    dp1=(pt3-pt2) x n
    

    so you got 2 axises:

    pnt0(t)=p0+dp0*t
    pnt1(u)=p1+dp1*u
    

    Where t,u are scalar parameters t,u=(-inf,+inf) it is just position in axis from the starting mid point ...

  2. the intersection is center of circle

    So find the intersection of 2 axises and call it pt0

  3. compute distance between center and any of your points

    r=|pt1-pt0|
    

曲线半径

抱歉,该图像适用于任何曲线(懒得为圆形重新画一遍,因为它们几乎相同)。如果您不知道点的顺序,则最远离彼此的两个点是外部点... 如果它们等距离,则顺序无关紧要,任何一个都可以。


感谢@Spektre的时间。我会采用你的解决方案,并告诉你结果。 - Mohamed Sirajudeen
@MohamedSirajudeen 好的,我刚刚注意到我只有一个单行参数,实际上应该有两个……一个对于每条轴线……我已经编辑过了(用t,u代替了只有t)。 - Spektre
1
你并不需要知道这些点的顺序,对吧?只需要确保它们是三个_不同的_点即可。 - Ángela
@Ángela 在经过一些思考后,我认为你是正确的,对于圆上的任意曲率,顺序并不重要...结果将是相同的(所以+1)。 - Spektre

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接