def applyDisplacement(self, point, displacement): displacement.append(0) m = GeoMath.Matrix(4, 4) m.matrix4Trans(displacement) point.append(1) pointModificated = m.mulPoint4ToMatrix4(point) point.pop() displacement.pop() pointModificated.pop() return pointModificated
def rotatePattern(self, axis, angle): middlePoint = GeoMath.getCenterEdge( [self.points[0], self.points[len(self.points) - 1]]) middlePoint.append(1) trans = GeoMath.Matrix(4, 4) trans.matrix4Trans(middlePoint) transIn = GeoMath.Matrix(4, 4) transIn.copy(trans) transIn.matrix4Inverse() for num in range(len(self.points)): pointRot = list(self.points[num]) pointRot.append(1) pointRot = transIn.mulPoint4ToMatrix4(pointRot) if (axis == [1, 0, 0]): Rx = GeoMath.Matrix(4, 4) Rx.singleRotx(angle) pointRot = Rx.mulPoint4ToMatrix4(pointRot) elif (axis == [0, 1, 0]): Ry = GeoMath.Matrix(4, 4) Ry.singleRoty(angle) pointRot = Ry.mulPoint4ToMatrix4(pointRot) else: Rz = GeoMath.Matrix(4, 4) Rz.singleRotz(angle) pointRot = Rz.mulPoint4ToMatrix4(pointRot) pointRot = trans.mulPoint4ToMatrix4(pointRot) self.points[num] = pointRot # Rotate normal logging.debug('Normal not rotated:' + str(self.normal)) to_rotate_normal = self.normal to_rotate_normal.append(0) if (axis == [1, 0, 0]): Rx = GeoMath.Matrix(4, 4) Rx.singleRotx(angle) normalRot = Rx.mulPoint4ToMatrix4(to_rotate_normal) elif (axis == [0, 1, 0]): Ry = GeoMath.Matrix(4, 4) Ry.singleRoty(angle) normalRot = Ry.mulPoint4ToMatrix4(to_rotate_normal) else: Rz = GeoMath.Matrix(4, 4) Rz.singleRotz(angle) normalRot = Rz.mulPoint4ToMatrix4(to_rotate_normal) normalRot.pop() logging.debug('Normal rotated: ' + str(normalRot)) self.normal = normalRot
def do(self, scale=False): # Calcule points to tbn matrix self.calculatePoints() # Get some arbitrary vectors conected from vertices of prim vec1 = GeoMath.vecSub(self.get_previous_point(), self.get_point_which_is_relative()) vec2 = GeoMath.vecSub(self.get_next_point(), self.get_point_which_is_relative()) # logging.debug('Two arbitrary vec1 and vec2:' + str(vec1) + ' ' + str(vec2)) # We have to know which angle reside between the two coencted vectors, to know if suposed vectors # in tangent space will be correct angle = GeoMath.vecDotProduct(vec1, vec2) / (GeoMath.vecModul(vec1) * GeoMath.vecModul(vec2)) angle = math.acos(angle) angle = math.degrees(angle) # logging.debug('Angle between vecs:' + str(angle)) # We put relative one arbitrary point to tangent space # logging.debug('Point relative:' + str(self.get_point_which_is_relative())) # Determine x and y vectors, now we'll have suposed horizontal and vertical vectors acording to # prim and direction of the crack hasTheNormalToY = GeoMath.vecDotProduct(list(self.get_prim().normal()), [0, 1, 0]) # logging.debug('Has the normal to y?:' + str(hasTheNormalToY)) if(hasTheNormalToY < (1 - epsilon) and hasTheNormalToY > (-1 + epsilon)): vecH, vecV = DetermineVectors.DetermineVectors.detVec(self.get_prim(), [0, 1, 0], [0, 0, 1]) # logging.debug('Yes, it has the normal to y and vecs are:' + str(vecH) + ' ' + str(vecV)) else: vecH, vecV = DetermineVectors.DetermineVectors.detVec(self.get_prim(), [0, 0, 1], [0, 0, 1]) # logging.debug('No, it isnt has the normal to y and vecs are:' + str(vecH) + ' ' + str(vecV)) # CHAPUZA CON NUMEROS COMPLEJOS!!! Precision de python pésima, 1.000000001>1?? no! y math.acos error cosAngle = GeoMath.vecDotProduct(vecH, vec1) / (GeoMath.vecModul(vec1) * GeoMath.vecModul(vecH)) complexAngle = cmath.acos(cosAngle) if(complexAngle.imag == 0): angleBetweenDetVecAndVecH = math.acos(cosAngle) else: if(cosAngle < 0): angleBetweenDetVecAndVecH = math.acos(-1) else: angleBetweenDetVecAndVecH = math.acos(1) # Now we have to ensure that the vec1 has the same direction that the horizontal vector, if not, we # change and the horizontal vector will be vec2. Also we have to check if the prim is not a quad, # in this case we have to get the vertical vector from horizontal vector, rotating the known angle # between the two vectors conected in prim (in quad we know that the angle is 90 and we already have the # good vectors) if((math.fabs(angleBetweenDetVecAndVecH) < epsilon) or (math.fabs(angleBetweenDetVecAndVecH) > (math.pi - epsilon))): if(scale): x = GeoMath.vecScalarProduct([1, 0, 0], GeoMath.vecModul(vec1)) x = [1, 0, 0] y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle) if(scale): y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec2)) tbn = GeoMath.createTBNmatrix(self.get_previous_point(), self.get_point_which_is_relative(), self.get_next_point(), x, [0, 0], y) else: if(scale): x = [1, 0, 0] y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle) if(scale): y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec1)) tbn = GeoMath.createTBNmatrix(self.get_previous_point(), self.get_point_which_is_relative(), self.get_next_point(), y, [0, 0], x) # logging.debug('tbn: ' + str(tbn.printAttributes())) tbnInverse = GeoMath.Matrix(3, 3) tbnInverse.copy(tbn) tbnInverse.matrix3Inverse() self.set_tbn(tbn) self.set_tbn_inverse(tbnInverse)