AlignTwoPolyDatas Example

In the function BestBoundingBox change:

  auto delta = 90.0;
  for (auto i = 0; i < 4; ++i)
  {
    ...

to suit what you want to do.

Remember also that you may need to reorient the target to get a better fit.