From: daid303 Date: Fri, 12 Apr 2013 08:03:09 +0000 (+0200) Subject: Add lay-flat code. X-Git-Tag: 13.05~107 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7192aabe55f35ccd9b13500beef308486bee15d1;p=cura.git Add lay-flat code. --- diff --git a/Cura/util/mesh.py b/Cura/util/mesh.py index 4aacc30f..c9d2236e 100644 --- a/Cura/util/mesh.py +++ b/Cura/util/mesh.py @@ -137,7 +137,47 @@ class printableObject(object): self.applyMatrix(numpy.matrix([[x,0,0],[0,y,0],[0,0,z]], numpy.float64)) def layFlat(self): - pass + transformedVertexes = (numpy.matrix(self._meshList[0].vertexes, copy = False) * self._matrix).getA() + minZvertex = transformedVertexes[transformedVertexes.argmin(0)[2]] + dotMin = 1.0 + dotV = None + for v in transformedVertexes: + diff = v - minZvertex + len = math.sqrt(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]) + if len < 5: + continue + dot = (diff[2] / len) + if dotMin > dot: + dotMin = dot + dotV = diff + if dotV is None: + return + rad = -math.atan2(dotV[1], dotV[0]) + self._matrix *= numpy.matrix([[math.cos(rad), math.sin(rad), 0], [-math.sin(rad), math.cos(rad), 0], [0,0,1]], numpy.float64) + rad = -math.asin(dotMin) + self._matrix *= numpy.matrix([[math.cos(rad), 0, math.sin(rad)], [0,1,0], [-math.sin(rad), 0, math.cos(rad)]], numpy.float64) + + + transformedVertexes = (numpy.matrix(self._meshList[0].vertexes, copy = False) * self._matrix).getA() + minZvertex = transformedVertexes[transformedVertexes.argmin(0)[2]] + dotMin = 1.0 + dotV = None + for v in transformedVertexes: + diff = v - minZvertex + len = math.sqrt(diff[1] * diff[1] + diff[2] * diff[2]) + if len < 5: + continue + dot = (diff[2] / len) + if dotMin > dot: + dotMin = dot + dotV = diff + if dotV is None: + return + if dotV[1] < 0: + rad = math.asin(dotMin) + else: + rad = -math.asin(dotMin) + self.applyMatrix(numpy.matrix([[1,0,0], [0, math.cos(rad), math.sin(rad)], [0, -math.sin(rad), math.cos(rad)]], numpy.float64)) def scaleUpTo(self, size): vMin = self._transformedMin