c# - Point Classification in a set of Bounding Boxes -


i have set of bounding boxes(rectangular) in 3d space. bounds of each box computed , stored in dictionary named "regionbounds". also, set of points populated in list named "pointstocategorize" given point(x,y,z) coordinates list populated , bounding box checked in, can check if point inside box or not. problem is, big dataset. number of points checked 1000 , no of bounding boxes 250-300. so, if loop through each bounding box each given point; total time takes 5-6 minutes. there efficient method process quicker ? if possible, small code great

public struct ibounds  {  public double x1, x2; public double y1, y2; public double z1, z2;  } public struct ipoint  {             public double x,y,z  }  dictionary<string, ibounds> regionbounds = new dictionary<string, ibounds>(); list<ipoint> pointstocategorize = new list<ipoint>();  int no_of_bounding_boxes = 300; int no_of_points_to_categorize = 1000;  (int = 1; <= no_of_bounding_boxes; i++) {    string boundingboxname = "bound_" + i;   ibounds boundingbox = new ibounds     {          x1 = computed other method , formulas,         x2 = computed other method , formulas,         y1 = computed other method , formulas,         y2 = computed other method , formulas,         z1 = computed other method , formulas,         z2 = computed other method , formulas      };      regionbounds.add(boundingboxname, boundingbox); }       ////////////start of output section /////////////////////////   for(int i= 1; < = pointstocategorize.count; i++){    foreach(var pair in regionbounds)    {      string myboxnmame = pair.key;      ibounds myboxbounds = pair.value;       console.writeline(pointinside(pointstocategorize[i],myboxbounds).tostring());    } }   ////////////// end of output section //////////////////  private bool pointinside(ipoint mypoint, ibounds boxtobecheckedin) {     if (mypoint.x > boxtobecheckedin.x1) && (mypoint.x < boxtobecheckedin.x2){         if (mypoint.y > boxtobecheckedin.y1) && (mypoint.y < boxtobecheckedin.y2){             if (mypoint.z > boxtobecheckedin.z1) && (mypoint.z < boxtobecheckedin.z2){                 return true;             }         }     }else{         return false;     }  } 

you may want use octree or kd-tree data structure, way more efficient iterating through all boxes.

see this article @ section 2-d orthogonal range searching, has resume of available techniques , algorithms, extendable 3d


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -