Search code examples
algorithmpolygon

how to calculate the bounding box of an arc?


I have an arc with three known points B(Xb,Yb), C(Xc,Yc), and D(Xd,Yd).B and C are the two endpoints of the arc, and D is a random control point on the arc. Now I need to get the minimum bounding box of this arc.

Please ignore the coordinates and grid points in the chart,arcs may be of any shape.

I am currently writing a C++ geometry library about arc polygons. Obtaining the bounding box of arc polygons is a relatively basic part of it. However, I have little experience in geometry and I was stumped in the first step. Is there any good calculation method? Thanks for your discussion and help.

Arc bounding box


Solution

  • The terms AABB (axis aligned bounding box), OBB (oriented bounding box) and MBR (minimum bounding rectangle = 2D bounding box), are not algorithms for finding bounding boxes, they are types of bounding boxes.

    Assuming that you are looking for an axis aligned box for an arc starting at point A, going through a point M and ending at point B, you can do the following steps which do not require any trigonometric functions:

    • use the coordinates of A,M,B to find the center C=[Cx,Cy] and radius r of the circle through points A,M,B using this answer and define the points

      E=[Cx+r,Cy]

      N=[Cx,Cy+r]

      W=[Cx-r,Cy]

      S=[Cx,Cy-r]

    • calculate the areas of the triangles ABM, ABE, ABN, ABW, ABS:

      ABM = (Ax*(By-My) + Bx*(My-Ay) + Mx*(Ay - By))/2

      ABE = (Ax*(By-Ey) + Bx*(Ey-Ay) + Ex*(Ay - By))/2

      ...

    • if ABM*ABE > 0 then BBxmax = Ex else BBxmax = max(Ax,Bx)

    • if ABM*ABN > 0 then BBymax = Ny else BBymax = max(Ay,By)

    • if ABM*ABW > 0 then BBxmin = Wx else BBxmin = min(Ax,Bx)

    • if ABM*ABS > 0 then BBymin = Sy else BBymin = min(Ay,By)

    After these steps, [BBxmin,BBymin] and [BBxmax,BBymax] should be the corners of the minimum axis aligned bounding box you are interested in.