ON_Box Transform

Hi,

I create ON_Box then orient it from one plane to another, but after the transformation the box size changes as if it is ON_BoundingBox. The box should be rotated in space. Why the ON_Box is not rotated properly?

    //Create bbox and box
    AABB = ON_BoundingBox::EmptyBoundingBox;
    p.GetTightBoundingBox(AABB);
    ON_Box OBB(AABB);

    //Orient box to 3D
    OBB.Transform(xformInv);

I am using following transformation:

    ON_Xform xformInv;
    xformInv.Rotation(planeXY, plane);

I am trying to compute aligned boundingbox from a list of points.
First I oriented all points to XY plane, Second, I made ON_BoundingBox. Third, I converted it to ON_Box. Fourth, I oriented the ON_Box back to 3D (this step fails). I tried with other transformations, ON_Box is acting like ON_BoundingBox. I check ON_Box Planes, in before and after transformation they remain XY planes.

Update:
I can only get it working when I transform plane, not the box itself:
OBB.plane.Transform(xformInv);

Hi @Petras_Vestartas,

This seems to work:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  ON_3dPoint bbox_min(ON_3dPoint::Origin);
  ON_3dPoint bbox_max(10.0, 10.0, 10.0);
  ON_BoundingBox bbox(ON_3dPoint::Origin, ON_3dPoint(10.0, 10.0, 10.0));

  ON_Box box(bbox);

  ON_SimpleArray<ON_3dPoint> corners;
  box.GetCorners(corners);

  RhinoApp().Print(L"Before transform\n");
  for (int i = 0; i < corners.Count(); i++)
  {
    ON_wString str;
    RhinoFormatPoint(corners[i], str);
    RhinoApp().Print(L"Corner %d = (%ls)\n", i, static_cast<const wchar_t*>(str));
  }

  ON_Plane plane(ON_Plane::World_xy);
  plane.Rotate(45.0 * (ON_PI / 180.0), plane.zaxis);

  ON_Xform xform;
  xform.Rotation(ON_Plane::World_xy, plane);

  box.Transform(xform);

  corners.Empty();
  box.GetCorners(corners);

  RhinoApp().Print(L"After transform\n");
  for (int i = 0; i < corners.Count(); i++)
  {
    ON_wString str;
    RhinoFormatPoint(corners[i], str);
    RhinoApp().Print(L"Corner %d = (%ls)\n", i, static_cast<const wchar_t*>(str));
  }

  return CRhinoCommand::success;
}
Before transform
Corner 0 = (0.000,0.000,0.000)
Corner 1 = (0.000,0.000,10.000)
Corner 2 = (0.000,10.000,0.000)
Corner 3 = (0.000,10.000,10.000)
Corner 4 = (10.000,0.000,0.000)
Corner 5 = (10.000,0.000,10.000)
Corner 6 = (10.000,10.000,0.000)
Corner 7 = (10.000,10.000,10.000)
After transform
Corner 0 = (-7.071,0.000,0.000)
Corner 1 = (-7.071,0.000,10.000)
Corner 2 = (-7.071,14.142,0.000)
Corner 3 = (-7.071,14.142,10.000)
Corner 4 = (7.071,0.000,0.000)
Corner 5 = (7.071,0.000,10.000)
Corner 6 = (7.071,14.142,0.000)
Corner 7 = (7.071,14.142,10.000)

– Dale

1 Like

Nope, I visualized these points in Grasshopper, and it is not working because the rotated box is still axis aligned. Can it be that the construction ON_Box box(bbox) somehow references the plane that is refercing ON_BoundingBox?

I get it working only when I rotate the plane the box itself.

This is your printed result (I assume it must be rotated 45 deg):