c# - Bounding box volume of an STL file -


i trying find bounding box volume of stl file using following code. of files working fine files gives strange result, means high x, y , z values. please me fix it.

enter code here      float length, breadth, height;             float minx = 0, maxx = 0,             miny=0, maxy=0,             minz=0, maxz=0;        public double signedvolumeoftriangle(float[] p1, float[] p2, float[] p3)     {         double v321 = p3[0] * p2[1] * p1[2];         double v231 = p2[0] * p3[1] * p1[2];         double v312 = p3[0] * p1[1] * p2[2];         double v132 = p1[0] * p3[1] * p2[2];         double v213 = p2[0] * p1[1] * p3[2];         double v123 = p1[0] * p2[1] * p3[2];         double vol = (1.0 / 6.0) * (-v321 + v231 + v312 - v132 - v213 + v123);           if (math.min(math.min(p1[0], p2[0]), p3[0]) < minx)         {             minx = math.min(math.min(p1[0], p2[0]), p3[0]);         }         else if (math.max(math.max(p1[0], p2[0]), p3[0]) > maxx)         {             maxx = math.max(math.max(p1[0], p2[0]), p3[0]);         }           if (math.min(math.min(p1[1], p2[1]), p3[1]) < miny)         {             miny = math.min(math.min(p1[1], p2[1]), p3[1]);         }         else if (math.max(math.max(p1[1], p2[1]), p3[1]) > maxy)         {             maxy = math.max(math.max(p1[1], p2[1]), p3[1]);         }          if (math.min(math.min(p1[2], p2[2]), p3[2]) < minz)         {             minz = math.min(math.min(p1[2], p2[2]), p3[2]);         }         else if (math.max(math.max(p1[2], p2[2]), p3[2]) > maxz)         {             maxz = math.max(math.max(p1[2], p2[2]), p3[2]);         }          return vol;     }      public float[] getboundingbox()     {         length = maxx - minx;         breadth = maxy - miny;         height = maxz - minz;         return new float[] { length, breadth, height };     } 

thanks

ayha

remove else. after computing min still need compute max.

also, getboundingbox returns dimension { length, breadth, height } of aabb. position relative (minx, miny, minz) lost.

finally, make sure global variables initialized correctly instance: minx=+infinity , maxx=-infinity, same y , z.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -