Given a number of curves,include line segments and circular arcs, how to compute the total OBB of all curves?
It seems that the union of each OBB of the individual curves does not right, it's not the minimal coverage.
Check this picture, how to compute the red box?
you should also add the input in vector form so we can test on your data ... I would approach like this:
O(n)
compute max distance in each angle
O(n)
just create table for enough
m
angles (like 5 deg step som = 360/5
) where for each angle section you remember max distant point distance only.compute max perpendicular distance for each rotation
O(m^2)
so for each angle section compute value that is:
where
i
covers+/- 90 deg
around actual section angle so now you got max perpendicular distances for each angle...pick best solution
O(m)
so look all rotations from 0 to 90 degrees and remember the one that has minimal OBB area. Just to be sure the OBB is aligned to section angle and size of axises is the
value
of that angle and all the 90 deg increments... around centerThis will not result in optimal solution but very close to it. To improve precision you can use more angle sections or even recursively search around found solution with smaller and smaller angle step (no need to compute the other angle areas after first run.
[Edit1]
I tried to code this in C++ as proof of concept and use your image (handled as set of points) as input so here the result so you got something to compare to (for debugging purposes)
gray are detected points from your image, green rectangle is axis aligned BBox the red rectangle is found OBBox. The aqua points are found max distance per angle interval and green dots are max perpendicular distance for
+/-90deg
neighbor angle intervals. I used400
angles and as you can see the result is pretty close ...360/400 deg
accuracy so this approach works well ...Here C++ source:
I used mine dynamic list template so:
List<double> xxx;
is the same asdouble xxx[];
xxx.add(5);
adds5
to end of the listxxx[7]
access array element (safe)xxx.dat[7]
access array element (unsafe but fast direct access)xxx.num
is the actual used size of the arrayxxx.reset()
clears the array and setxxx.num=0
xxx.allocate(100)
preallocate space for100
itemsYou can ignore the
// convert bmp -> pnt[]
VCL part as you got your data already.