mathformula

formula to calculate bounding coordinates of an arc in space


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

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.

bounding coordinates of an arc in space

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.

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.

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.


Solution

  • 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)
    

    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);
    }
    

    Testing

    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