# Differences

This shows you the differences between two versions of the page.

 — developer:sdksamples:isbrepbox [2015/09/14] (current) Line 1: Line 1: + ====== Determining if a Brep is a Box ====== + ====== C++, .NET ====== + > **Summary:​** //Discusses how to determine if a brep object is a box.// + + =====Question===== + How can I determine whether or not a polysurface is a (brep) box? + + =====Answer===== + For a polysurface to be a box, the following conditions must be true: + + - The brep must be solid. + - The brep must have six faces. + - Each of the six faces must be planar. + - Each of the planar face must be either perpendicular or antiparallel to the other planar faces. + + The follwing sample functions demonstrate how to determine whether or not a polysurface is a box. + + ===== C++ ===== + + + bool IsBrepBox( const ON_Brep&​ brep ) + { + double zero_tolerance = 1.0e-6; // or whatever + ON_3dVector N[6]; + + bool rc = brep.IsSolid();​ + + if (rc) + rc = (brep.m_F.Count() == 6); + + if (rc) + { + for (int i = 0; rc && i < 6; i++) + { + ON_Plane plane; + if (brep.m_F[i].IsPlanar(&​plane,​ zero_tolerance)) + { + N[i] = plane.zaxis;​ + N[i].Unitize();​ + } + else + rc = false; + } + } + + if (rc) + { + for (int i = 0; rc && i < 6; i++) + { + int count = 0; + for (int j = 0; rc && j < 6; j++) + { + double dot = fabs(N[i] * N[j]); + if (fabs(dot) <= zero_tolerance) + continue; + if (fabs(dot - 1.0) <= zero_tolerance) ​ + count++; + else + rc = false; + } + + if (rc) + { + if (2 != count) + rc = false; + } + } + } + + return rc; + } + + ​ + ===== C# ===== + + + public bool IsBrepBox( IOnBrep brep ) + { + if (brep == null) + return false; + + double tolerance = 1.0e-6; // or whatever + On3dVector[] N = new On3dVector[6];​ + + bool rc = brep.IsSolid();​ + + if (rc) + rc = (brep.m_F.Count() == 6); + + if (rc) + { + for (int i = 0; rc && i < 6; i++) + { + OnPlane plane = new OnPlane(); + if (brep.m_F[i].IsPlanar(plane,​ tolerance)) + { + N[i] = plane.zaxis;​ + N[i].Unitize();​ + } + else + rc = false; + } + } + + if (rc) + { + for (int i = 0; rc && i < 6; i++) + { + int count = 0; + for (int j = 0; rc && j < 6; j++ ) + { + double dot = Math.Abs(N[i] * N[j]); + if (Math.Abs(dot) <= tolerance) + continue; + if (Math.Abs(dot - 1.0) <= tolerance) ​ + count++; + else + rc = false; + } + + if (rc) + { + if (2 != count) + rc = false; + } + } + } + + return rc; + } + ​ + + + {{tag>​Developer cplusplus dotnet}}
developer/sdksamples/isbrepbox.txt ยท Last modified: 2015/09/14 (external edit)