计算空间中弧的边界坐标的公式 [英] formula to calculate bounding coordinates of an arc in space

查看:181
本文介绍了计算空间中弧的边界坐标的公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2条线相交于具有已知坐标的点 -x1,y1 -x2,y2 -x3,y3

I have 2 lines that intersect at a point with know coordinates - x1,y1 - x2,y2 - x3,y3

据此,我计算了线之间给定半径的圆弧.所以我现在知道 -2个弧形端点x4,y4和x5,y5 -圆弧中心点Cx,Cy -圆弧半径r -相对于极轴的X轴的起始和终止角,因此线之间的夹角.

From this I have calculated an arc at a given radius between the lines. So I now know - 2 arc endpoints x4,y4 and x5,y5 - arc centrepoint Cx,Cy - arc radius r - starting and ending angles relative to the X axis in polar and therefore the angle between the lines.

我想创建一个公式,该公式将计算圆弧的最大和最小X和Y值. IE.包围圆弧的盒子的坐标.

I want to create a formula that will calculate the maximum and minimum X and Y values of the arc. I.e. the coordinates of the box that would enclose the arc.

在下面的示例中,我可以找出最小X值和最大Y值,它们是已知值,但是不确定如何计算最大X和最小Y.

In the example below I can find out the minimum X value and maximum Y value, they are known values, but am unsure how to calculate the maximum X and minimum Y.

在其他情况下,弧可以是任何坐标,因此已知的最小值和最大值将发生变化.

In other instances the arc could be any coordinates so the known minimum and maximum values will change.

我知道如何以给定角度或间隔计算沿圆弧的点,但不计算特定方向(在这种情况下为X和Y轴)上的最大值和最小值.

I know how to calculate points along an arc at a given angle or intervals but not the maximum and minimum in a particular direction, in this case X and Y axis.

我将在编程中使用该公式.

I am going to use the formula in programming.

推荐答案

我有一个可以尝试使用的算法解决方案.它包括扫描弧上已知起点和终点之间的极坐标空间,并跟踪最小值和最大值.

I have an algorithmic solution you can try using. It involves scanning the polar coordinate space in between your known starting and ending points on the arc, and keeping track of the minimum and maximum values.

以下是该算法的基本步骤:

Here are the basic steps of the algorithm:

  • 将圆弧上的两个输入(笛卡尔)点转换为极坐标
  • 在极坐标中逆时针沿着弧线行走
  • 在每个步骤中,转换回笛卡尔坐标并检查最小值/最大值

我利用以下两个方程式将极坐标转换为笛卡尔坐标:

I took advantage of the following two equations to convert polar to Cartedian coordinates:

x = r*cosθ
y = r*sinθ

这里是将笛卡尔坐标转换为极角的方程式:

Here is an equation to convert Cartesian coordinates to a polar angle:

θ = tan-1(y / x)

您需要注意该方程中的电位除以零.无穷大的反正切为Pi / 2弧度.

You need to watch out for the potential divide by zero in this equation. Arc tangent of infinity is Pi / 2 radians.

此解决方案假定弧线从低弧度值开始向高弧度值逆时针移动.

This solution assumes that an arc begins and traverses counter-clockwise from a low radian value to a high radian value.

// Input Parameters:
// (x1, y1) first point on arc
// (x2, y2) second point on arc
// (xc, yc) center point of circle

public void findMinMax(double x1, double x2, double y1, double y2, double xc, double yc) {
    double xMin, yMin, xMax, yMax;
    // compute radius of circle
    double radius = Math.sqrt(Math.pow((xc - x1), 2) + Math.pow((yc - y1), 2));

    // compute starting and ending points in polar coordinates
    double t1 = 0.0;
    if (x1 == 0.0) {
        t1 = Math.PI / 2;
    }
    else {
        t1 = Math.atan(y1 / x1);
    }

    double t2 = 0.0;
    if (x2 == 0.0) {
        t2 = Math.PI / 2;
    }
    else {
        t2 = Math.atan(y2 / x2);
    }

    // determine starting and ending polar angles
    double tStart, tEnd;
    if (t1 < t2) {
        tStart = t1;
        tEnd = t2;
    }
    else {
        tStart = t2;
        tEnd = t1;
    }

    // now scan the polar space at fixed radius and find
    // the minimum AND maximum Cartesian x and y values
    double delta = 0.01;

    // initialize min and max coordinates to first point
    xMin = radius * Math.cos(tStart);
    yMin = radius * Math.sin(tStart);
    xMax = xMin;
    yMax = yMin;

    for (double theta=tStart; theta < tEnd; theta += delta) {
        // compute coordinates
        double x = radius * Math.cos(theta);
        double y = radius * Math.sin(theta);

        if (x > xMax) {
            xMax = x;
        }
        if (x < xMin) {
            xMin = x;
        }
        if (y > yMax) {
            yMax = y;
        }
        if (y < yMin) {
            yMin = y;
        }
    }

    // display min and max values
    System.out.println("xMin = " + xMin + ", yMin = " + yMin);
    System.out.println("xMax = " + xMax + ", yMax = " + yMax);
}

测试

Arc starting at (5, 0) and ending at (0, 5) with center point (0, 0)
findMinMax(5, 0, 0, 5, 0, 0)
xMin = 0.003981633553660766, yMin = 0.0
xMax = 5.0, yMax = 4.999998414659173

这篇关于计算空间中弧的边界坐标的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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