当前位置: 首页>>代码示例>>Python>>正文


Python GeoMath.vecModul方法代码示例

本文整理汇总了Python中lib.GeoMath.vecModul方法的典型用法代码示例。如果您正苦于以下问题:Python GeoMath.vecModul方法的具体用法?Python GeoMath.vecModul怎么用?Python GeoMath.vecModul使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.GeoMath的用法示例。


在下文中一共展示了GeoMath.vecModul方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: goToPrimPattern

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def goToPrimPattern(self, curPoint, nextPoint, pat, tbn, pointWhichIsRelative):
        '''
        TBN aplication
        '''
        global epsilon
        for num in range(len(pat.points)):
            pat.points[num] = tbn.mulPoint3ToMatrix3(pat.points[num])
            pat.points[num] = GeoMath.vecPlus(pointWhichIsRelative, pat.points[num])
        # Transform normal vector also
        logging.debug("Changing normal" + str(pat.getNormal()))
        transformed_normal = tbn.mulPoint3ToMatrix3(pat.getNormal())
        logging.debug("Transformed normal" + str(transformed_normal))
        normalized_normal = GeoMath.vecNormalize(transformed_normal)
        logging.debug("normalized normal" + str(normalized_normal))
        pat.setNormal(normalized_normal)
        logging.debug("normalized normal set?? " + str(pat.getNormal()))
        trans = GeoMath.vecSub(curPoint, pat.getFirstPoint())
        likelyPointF = GeoMath.vecPlus(pat.getLastPoint(), trans)
        if(GeoMath.vecModul(GeoMath.vecSub(likelyPointF, nextPoint)) > epsilon):
            trans = GeoMath.vecSub(curPoint, pat.getLastPoint())

        for num in range(len(pat.getPoints())):
            pat.points[num] = self.translatePointToPrim(pat.points[num], trans)

        if(GeoMath.vecModul(GeoMath.vecSub(likelyPointF, nextPoint)) > epsilon):
            pat.points.reverse()
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:28,代码来源:AutoPattern.py

示例2: bresenham

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
 def bresenham(Ipoint, point1, fPoint, xSize, ySize, prim, exception):
     reload (GeoMath)
     reload (DetermineVectors)
     reload (Validator)
     curPoint = point1
     dirVec = GeoMath.vecNormalize(GeoMath.vecSub(fPoint, Ipoint))
     # Get the horizontal and vertical vectors
     xVec, yVec = DetermineVectors.DetermineVectors.detVec(prim, dirVec, exception)
     xSizeVec = GeoMath.vecScalarProduct(xVec, xSize)
     ySizeVec = GeoMath.vecScalarProduct(yVec, ySize)
     vecToFinal = GeoMath.vecSub(curPoint, fPoint)
     sizeToFinalx = abs(GeoMath.vecDotProduct(vecToFinal, xVec) / GeoMath.vecModul(xVec))
     sizeToFinaly = abs(GeoMath.vecDotProduct(vecToFinal, yVec) / GeoMath.vecModul(yVec))
     if(sizeToFinalx > xSize or sizeToFinaly > ySize):
         pointx = GeoMath.vecPlus(curPoint, xSizeVec)
         pointy = GeoMath.vecPlus(curPoint, ySizeVec)
         pointxy = GeoMath.vecPlus(curPoint, xSizeVec)
         pointxy = GeoMath.vecPlus(pointxy, ySizeVec)
         curxVec = GeoMath.vecNormalize(GeoMath.vecSub(pointx, Ipoint))
         curyVec = GeoMath.vecNormalize(GeoMath.vecSub(pointy, Ipoint))
         curxyVec = GeoMath.vecNormalize(GeoMath.vecSub(pointxy, Ipoint))
         # We get the max dot product, the vector nearest to line
         dotx = GeoMath.vecDotProduct(curxVec, dirVec)
         doty = GeoMath.vecDotProduct(curyVec, dirVec)
         dotxy = GeoMath.vecDotProduct(curxyVec, dirVec)
         pointsTemp = {}
         if(Validator.Validator.pointInsidePrim(pointx, prim)): pointsTemp[dotx] = pointx
         if(Validator.Validator.pointInsidePrim(pointy, prim)): pointsTemp[doty] = pointy
         if(Validator.Validator.pointInsidePrim(pointxy, prim)): pointsTemp[dotxy] = pointxy
         if(not pointsTemp):
             point = list(fPoint)
         else:
             bestPoint = list(pointsTemp[sorted(pointsTemp)[len(pointsTemp) - 1]])
             point = bestPoint
     else:
         point = list(fPoint)
         '''   
         if(prim.number()==54):
         print "Ipoint, fpoint"
         print Ipoint, fPoint
         print "pointx, pointy, pointxy"
         print pointx, pointy, pointxy
         print "Dots"
         print dotx, doty, dotxy
         print "sizes"
         print sizeToFinalx, sizeToFinaly            
         print "Point"
         print point
         '''
     return point
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:52,代码来源:Bresenham.py

示例3: applyJoker

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
 def applyJoker(self, point1, point2, vecH, vecV):
     vec = GeoMath.vecSub(point2, point1)
     dotH = GeoMath.vecDotProduct(vec, vecH) / GeoMath.vecModul(vecH)
     dotV = GeoMath.vecDotProduct(vec, vecV) / GeoMath.vecModul(vecV)
     if(math.fabs(dotH) < math.fabs(dotV)):
         normal = GeoMath.vecNormalize(vecH)
     else:
         normal = GeoMath.vecNormalize(vecV)
     norV = GeoMath.vecNormalize(vecV)
     norH = GeoMath.vecNormalize(vecH)
     sizeX = GeoMath.vecModul(GeoMath.vecScalarProduct(norH, dotH))
     sizeY = GeoMath.vecModul(GeoMath.vecScalarProduct(norV, dotV))
     pointI1 = GeoMath.vecPlus(point1, GeoMath.vecScalarProduct(norH, dotH / 2))
     pointI2 = GeoMath.vecPlus(pointI1, GeoMath.vecScalarProduct(norV, dotV))
     return WallPattern(normal, [list(point1), pointI1, pointI2, list(point2)], [sizeX, sizeY], 0)
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:17,代码来源:Data.py

示例4: create_grid

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def create_grid(self, floor_):
        global FLOOR_SIZE
        reload(HouInterface)

        points = floor_.get_absolute_points()
        center = GeoMath.centerOfPoints(points)

        vec1 = GeoMath.vecSub(points[0], points[1])
        vec2 = GeoMath.vecSub(points[2], points[1])

        if (vec1[0] != 0):
            vecx = GeoMath.vecModul(vec1)
            vecz = GeoMath.vecModul(vec2)
        else:
            vecx = GeoMath.vecModul(vec2)
            vecz = GeoMath.vecModul(vec1)
        columns = vecx / TILE_SIZE
        rows = vecz / TILE_SIZE
        gridName = self.hout.showGrid('floor', center, vecx, vecz, rows, columns)

        return gridName
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:23,代码来源:destroyfloorstructure.py

示例5: checkTexture

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def checkTexture(self, texture, previousTexture, genPattern, Fpoint, nextPoint):

        tex, nearestPointIntersect, minDistance = texture.findIntersectionWithNearestTexture(genPattern.getPoints())
        logging.debug("Start method checkTexture, class Crack")
        if(tex):
            logging.debug('nearestPointIntersect: ' + str(nearestPointIntersect) + 'Distance: ' + str(minDistance) + 'Texture: ' + str(tex.get_material().get_name()))
        else:
            logging.debug('nearestPointIntersect: ' + str(nearestPointIntersect) + 'Distance: ' + str(minDistance) + 'No Texture')

        # If we found some interect point we clip the pattern to this point
        if(nearestPointIntersect):
            achieved = genPattern.clipPattern(nearestPointIntersect)
            if(not achieved):
                logging.error("No clipping achieved")
                return None, previousTexture
        else:
            return None, previousTexture
        # Now we have to ensure that the next texture is correct, because possibly the intersection
        # is correct and the next texture in pattern direction is correct, but maybe the direction
        # has changed due to the clipping of the pattern and the point clipped. The direction now is
        # the direction between point clipped-intersected with next texture and the final point of
        # the crack in prim.
        # also, in the NORMAL case, maybe the pattern intersect with his texture, because are exiting
        # from it, so we have to do a point in polygon to search what texture is the next

        # Check texture, for do that get the vector direction and do it little and do a point in
        # polygon with the texture
        nextDir = GeoMath.vecSub(Fpoint, nearestPointIntersect)
        logging.debug('next dir before', str(nextDir))
        if(GeoMath.vecModul(nextDir) > 0):
            nextDir = GeoMath.vecNormalize(nextDir)
            # make it little, not more little than the epsilon used at GeoMath pointInSegmentDistance method,
            # so we use a 10x bigger than epsilon, so 0.05
            nextDir = GeoMath.vecScalarProduct(nextDir, 0.05)
            nextPoint = GeoMath.vecPlus(nextDir, nearestPointIntersect)
            nextTex = texture.findUpperTextureContainingPoint(nextPoint)
            logging.debug('Direction and texture , next point: %s, next direction', str(nextPoint), str(nextDir))
        else:
            nextTex = None
            # We get the final point, so we not have to ensure anything


        logging.debug("End method checkTexture, class Crack")
        if(nearestPointIntersect):
            self.intersectionPoints.append(nearestPointIntersect)
        return nearestPointIntersect, nextTex
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:48,代码来源:crack.py

示例6: getPossiblePatterns

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def getPossiblePatterns(self, curPoint, nextPoint, setClass, epsilon, setPat, vector, vectorRotated, pat):
        match = False
        goodPattern = None
        copyPat = pat.copy()
        vecPat = GeoMath.vecSub(copyPat.points[len(copyPat.points) - 1], copyPat.points[0])
        vecPatIn = GeoMath.vecSub(copyPat.points[0], pat.points[len(copyPat.points) - 1])
        logging.debug("Index pat %s", str(setPat.index(pat)))
        logging.debug("Vectors")
        logging.debug("Vector in prim %s", str(vector))
        logging.debug("Pattern vector %s", str(vecPat))
        logging.debug("Vector rotated %s", str(vectorRotated))
        logging.debug("Curpooint %s", str(curPoint))
        logging.debug("NextPoint %s", str(nextPoint))
        # Same length
        if (math.fabs(GeoMath.vecModul(vecPat) - GeoMath.vecModul(vectorRotated)) < epsilon):
            rest = GeoMath.vecSub(vectorRotated, vecPat)
            restIn = GeoMath.vecSub(vectorRotated, vecPatIn)
            # Same direction
            if ((GeoMath.vecModul(rest) < epsilon) or (GeoMath.vecModul(restIn) < epsilon)):
                goodPattern = copyPat
                match = True  # No same direction
            if (match == False):
                '''
            See simetry in this order:
            1-rot in z
            2-rot in y
            3-rot in x
            '''
                anglez = setClass.getRotz()
                if (anglez != 0):
                    Rzva = GeoMath.Matrix(4, 4)
                    Rzva.singleRotz(anglez)
                    copyVecPat = list(vecPat)
                    copyVecPat.append(0)
                    numRotations = 0
                    if (anglez == 0):
                        maxRot = 0
                    else:
                        maxRot = (360 / anglez) - 1
                    while numRotations < (maxRot) and not match:
                        copyVecPat = Rzva.mulPoint4ToMatrix4(copyVecPat)  # Not necesary to delete the last number in vector(which added for homogeneous)
                        restRz = GeoMath.vecSub(copyVecPat, vectorRotated)
                        restInRz = GeoMath.vecSub(GeoMath.vecSub([0, 0, 0], copyVecPat), vectorRotated)
                        numRotations += 1

                    if ((numRotations <= maxRot) and (GeoMath.vecModul(restRz) < epsilon or GeoMath.vecModul(restInRz) < epsilon)):
                        anglezTot = numRotations * anglez
                        copyPat.rotatePattern([0, 0, 1], anglezTot)
                        goodPattern = copyPat
                        match = True
                # Rotation in y if in z is not valid
                simRoty = setClass.getSimY(copyPat)
                if (not match and simRoty):
                    Ry = GeoMath.Matrix(4, 4)
                    Ry.singleRoty(180)
                    copyVecPat = list(vecPat)
                    copyVecPatIn = list(vecPatIn)
                    copyVecPat.append(0)
                    copyVecPatIn.append(0)
                    copyVecPat = Ry.mulPoint4ToMatrix4(copyVecPat)
                    copyVecPatIn = Ry.mulPoint4ToMatrix4(copyVecPatIn)  # Not necesary to delete the last number in vector(which added for homogeneous)
                    restRy = GeoMath.vecSub(copyVecPat, vectorRotated)
                    restRyIn = GeoMath.vecSub(copyVecPatIn, vectorRotated)
                    if (GeoMath.vecModul(restRy) < epsilon or (GeoMath.vecModul(restRyIn) < epsilon)):
                        copyPat.rotatePattern([0, 1, 0], 180)
                        goodPattern = copyPat
                        match = True  # Rotation in x if in z neither y is valid
                simRotx = setClass.getSimX(copyPat)
                if (not match and simRotx):
                    Rx = GeoMath.Matrix(4, 4)
                    Rx.singleRotx(180)
                    copyVecPat = list(vecPat)
                    copyVecPatIn = list(vecPatIn)
                    copyVecPat.append(0)
                    copyVecPatIn.append(0)
                    copyVecPat = Rx.mulPoint4ToMatrix4(copyVecPat)
                    copyVecPatIn = Rx.mulPoint4ToMatrix4(copyVecPatIn)  # Not necesary to delete the last number in vector(which added for homogeneous)
                    restRx = GeoMath.vecSub(copyVecPat, vectorRotated)
                    restRxIn = GeoMath.vecSub(copyVecPatIn, vectorRotated)
                    if (GeoMath.vecModul(restRx) < epsilon or (GeoMath.vecModul(restRxIn) < epsilon)):
                        copyPat.rotatePattern([1, 0, 0], 180)
                        goodPattern = copyPat
                        match = True
        return goodPattern
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:86,代码来源:AutoPattern.py

示例7: find_path

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def find_path(self, gridName, startPoint, finalPoint):
        reload(GeoMath)
        path = []
        grid = self.hout.grids[gridName][0]
        logging.debug('grid name ' + str(grid))
        prims = grid.geometry().prims()
        startPrim, finalPrim = self.findExtremePrims(startPoint, finalPoint, prims)
        if (startPrim == None or finalPrim == None):
            logging.debug("Start and final prims can't be ensured since the intersections_with_crack with the crack are a little misplaced, and that cause pointInEdge to fail when trying to know which primitive is the start and the final")
        # Unique prim
        if (finalPrim.number() == startPrim.number()):
            uniquePrim = InfoPathPrim.InfoPathPrim(startPrim)
            uniquePrim.setiPoint(startPoint)
            uniquePrim.setfPoint(finalPoint)
            return [uniquePrim]
            
        logging.debug("prims with floor " + str(
            [startPrim.number(), finalPrim.number()]))
        navigationLine = GeoMath.vecSub(finalPoint, startPoint)

        mappedStartPoint = [startPoint[0], startPoint[2], 0]
        mappedFinalPoint = [finalPoint[0], finalPoint[2], 0]

        primsInPath = []
        for prim in prims:
            if (prim.number() == startPrim.number() or prim.number() == finalPrim.number()):
                continue
            edges = GeoMath.getEdgesFromPrim(prim)
            mappedEdges = [[[edge[0][0], edge[0][2], 0], [edge[1][0], edge[1][2], 0]]
                           for edge in edges]
            logging.debug("prim number " + str(prim.number()))
            inters = GeoMath.getIntersectionsBetweenEdges2D(
                mappedEdges, [[mappedStartPoint, mappedFinalPoint]])

            if (inters):
                logging.debug("Inter in path " + str(inters))
                # Demap again to original 'y' component, which both start point or
                # final point have
                demappedInters = [[inter[0], startPoint[1], inter[1]]
                                for inter in inters]
                distPoint0 = GeoMath.vecModul(
                    GeoMath.vecSub(demappedInters[0], startPoint))
                distPoint1 = GeoMath.vecModul(
                    GeoMath.vecSub(demappedInters[1], startPoint))
                if (distPoint0 < distPoint1):
                    startPrimPoint = demappedInters[0]
                    finalPrimPoint = demappedInters[1]
                else:
                    startPrimPoint = demappedInters[1]
                    finalPrimPoint = demappedInters[0]
                infoPrim = InfoPathPrim.InfoPathPrim(prim)
                infoPrim.setiPoint(startPrimPoint)
                infoPrim.setfPoint(finalPrimPoint)
                primsInPath.append(infoPrim)
                logging.debug("Prim intersects " + str(prim.number()) + " " + str(startPrimPoint) + " " + str(finalPrimPoint)) 

        sorted(primsInPath, key=lambda infoPrim:
               GeoMath.vecModul(GeoMath.vecSub(infoPrim.iPoint, startPoint)))
        logging.debug("Testing??")
        if (not primsInPath):
            logging.debug("No intersections " + str(primsInPath))
            return
            
        startInfoPrim = InfoPathPrim.InfoPathPrim(startPrim)
        finalInfoPrim = InfoPathPrim. InfoPathPrim(finalPrim)
        
        startInfoPrim.setiPoint(startPoint)
        startInfoPrim.setfPoint(primsInPath[0].iPoint)
        finalInfoPrim.setiPoint(primsInPath[len(primsInPath) - 1].fPoint)
        finalInfoPrim.setfPoint(finalPoint)
        
        primsInPath.append(finalInfoPrim)
        primsInPath.insert(0, startInfoPrim)
        
        logging.debug([prim.prim.number() for prim in primsInPath])
        
        #DEBUG:
        logging.debug("Before showing path")
        self.showPath(gridName, InfoPathPrim.convertListFromInfoPrimToPrim(primsInPath))
        
        return primsInPath
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:83,代码来源:destroyfloorstructure.py

示例8: do

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    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)
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:71,代码来源:CreateTBN.py

示例9: add_noise

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
 def add_noise(self, height, frequency, for_edge):
     if(GeoMath.vecModul(self.getNormal()) > 0):
         # If normal of pattern is valid
         ad = Add_noise()
         self.points = ad.apply_noise(self.points, self.normal, height, for_edge, frequency)
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:7,代码来源:Data.py

示例10: defCrack

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def defCrack(self, prim, Ipoint, Fpoint, texturePrim):
        reload(AutoPattern)
        reload(Bresenham)
        reload(Data)
        reload(GeoMath)
        reload(HouInterface)
        global epsilon
        global primnumber
        # TEMP: only for debug the patterns
        # Size x and size y is the valor of some material with the minor wavelength(bigger pattern)
        curPoint = Ipoint
        self.patternCrack[prim] = []
        vertices = [list(p.point().position()) for p in prim.vertices()]
        print "vertices"
        print vertices
        # Convert prim to tangent space of patterns
        # Get some arbitrary vectors conected from vertices of prim
        vec1 = GeoMath.vecSub(vertices[0], vertices[1])
        vec2 = GeoMath.vecSub(vertices[2], vertices[1])
        # 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)

        # We put relative one arbitrary point to tangent space
        pointWhichIsRelative = vertices[1]
        # Determine x and y vectors, now we'll have suposed horizontal and vertical vectors acording to
        # prim and direction of the crack

        vecH, vecV = DetermineVectors.DetermineVectors.detVec(prim, GeoMath.vecSub(Ipoint, Fpoint), [0, 0, 1])
        # 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)
        #=======================================================================
        print "Create TBN"
        if((math.fabs(angleBetweenDetVecAndVecH) < epsilon) or (math.fabs(angleBetweenDetVecAndVecH) > (math.pi - epsilon))):
            x = GeoMath.vecScalarProduct([1, 0, 0], GeoMath.vecModul(vec1))
            y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle)
            y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec2))
            tbn = GeoMath.createTBNmatrix(vertices[0], vertices[1], vertices[2], x, [0, 0], y)
        else:
            x = GeoMath.vecScalarProduct([1, 0, 0], GeoMath.vecModul(vec2))
            y = GeoMath.rotateVecByVec(x, [0, 0, 1], angle)
            y = GeoMath.vecScalarProduct(GeoMath.vecNormalize(y), GeoMath.vecModul(vec1))
            tbn = GeoMath.createTBNmatrix(vertices[0], vertices[1], vertices[2], y, [0, 0], x)

        print "Edn create tbn"
        tbnInverse = GeoMath.Matrix(3, 3)
        tbnInverse.copy(tbn)
        tbnInverse.matrix3Inverse()

        # Get the first material:
        print "texture get first layer"
        texture = texturePrim.getFirstLayer(Ipoint)
        nextMaterial = texture.get_material()
        print "end get material"
        # Create status of the process to show to the user
        distance_to_complete = GeoMath.vecModul(GeoMath.vecSub(curPoint, Fpoint))
        ui_process_status = UIProcessStatus.UIProcessStatus('crack for prim',
                                                                distance_to_complete)
        while(GeoMath.vecModul(GeoMath.vecSub(curPoint, Fpoint)) > epsilon):
            # Print status of the process
            dist = GeoMath.vecModul(GeoMath.vecSub(curPoint, Fpoint))
            ui_process_status.calculate_status(dist, inverse=True)
            ui_process_status.print_status()

            genPattern = Data.GeneralPattern()
            for wavelength in nextMaterial.mat.keys():
                singleMat = nextMaterial.mat[wavelength]
                setOfTypeOfPattern = CDF.cdf([[singleMat.classesAndPercentage[k], k] for k in singleMat.classesAndPercentage.keys()])
                if(wavelength == 0):
                    nextPoint = Bresenham.Bresenham.bresenham(Ipoint, curPoint, Fpoint, setOfTypeOfPattern.getSizex(), setOfTypeOfPattern.getSizey(), prim, [1, 0, 0])
                    pat = AutoPattern.AutoPattern(curPoint, nextPoint, setOfTypeOfPattern, prim, wavelength, self.patternCrack, tbn, tbnInverse, pointWhichIsRelative, texture, texturePrim).pattern
                genPattern.applyPattern(pat, wavelength)

            # Check texture
            previousTexture = texture
            pii, texture = self.checkTexture(texturePrim, previousTexture, genPattern, Fpoint, nextPoint)
            logging.debug('Pii defcrack: ' + str(pii))
            logging.debug('CurPoint defcrack: ' + str(curPoint))
            logging.debug('genPattern ' + str(genPattern.getPoints()))
            '''
            if(not curPoint):
                curPoint=genPattern.getLastPoint()
#.........这里部分代码省略.........
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:103,代码来源:crack.py

示例11: intersect_bounding_box_without_limits_3D

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def intersect_bounding_box_without_limits_3D(self, bounding_box, DISPLAY=False):
        global littleEpsilon
        try:
            if not self.get_prim():
                raise Errors.CantBeNoneError("Prim cant be none", "We need a prim to calculate tbn some steps after")
        except Errors.CantBeNoneError as e:
            Errors.Error.display_exception(e)
            exit()

        if not self.get_points_tangent_space():
            self.convert_3D_to_2D(self.get_prim())
        this_point_relative = self.get_tbn_class().get_point_which_is_relative()
        this_tbn_inverse_matrix = self.get_tbn_class().get_tbn_inverse()
        param_bounding_box_points_in_this_tangent_space = []
        for point in bounding_box.get_rectangle_object_space():
            point_relative = GeoMath.vecSub(point, this_point_relative)
            point_tangent_space = this_tbn_inverse_matrix.mulPoint3ToMatrix3(point_relative)
            param_bounding_box_points_in_this_tangent_space.append(point_tangent_space)
        intersections = GeoMath.getIntersectionsBetweenEdges2D(
            self.get_edges_tangent_space(), GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space)
        )
        if intersections:
            # ===============================================================
            # Check if the limits are touching and if it are touching it,
            # check if the intersection is in there. If it is in there,
            # the intersection lie in the limit, so we dont consider an
            # intersection
            # ===============================================================
            edges_shared_between_bounding_boxes = GeoMath.getEdgesBetweenEdges(
                self.get_edges_tangent_space(),
                GeoMath.getEdgesFromPoints(param_bounding_box_points_in_this_tangent_space),
            )
            inside = False
            print "Edges shared between"
            print edges_shared_between_bounding_boxes
            for intersection in intersections:
                inside = GeoMath.pointInEdges(intersection, edges_shared_between_bounding_boxes)
                if not inside:
                    break
            # ===============================================================
            # If all intersections lie in the edges shared between bounding
            # boxes we discart its
            # ===============================================================
            if inside:
                intersections = []
            else:
                # check if intersections are in the corner, because we consider corner as limit
                shared_points_between_bounding_boxes = GeoMath.getSharedPoints(
                    self.get_rectangle_tangent_space(), param_bounding_box_points_in_this_tangent_space
                )
                # If all intersections lie in the corner we doen't consider intersections as intersections
                true_intersections = list(intersections)
                for intersection in intersections:
                    for corner in shared_points_between_bounding_boxes:
                        if GeoMath.vecModul(GeoMath.vecSub(corner, intersection)) <= littleEpsilon:
                            true_intersections.remove(intersection)
                            break
                intersections = true_intersections

        if DISPLAY:
            # TEMP: exit
            1 / 0
            exit()
            for intersection in intersections:
                this_tbn_matrix = self.get_tbn_class().get_tbn()
                point_object_space = this_tbn_matrix.mulPoint3ToMatrix3(intersection)
                point_absolute = GeoMath.vecPlus(point_object_space, this_point_relative)
                self.to_display_intersections.append(point_absolute)
            self.display_intersections()
        return intersections
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:72,代码来源:BoundingBox.py

示例12: checkIntersectionWithTexture

# 需要导入模块: from lib import GeoMath [as 别名]
# 或者: from lib.GeoMath import vecModul [as 别名]
    def checkIntersectionWithTexture(self, points, prim):
        global DEBUG
        global epsilon
        logging.debug("Start method checkIntersectionWithTexture, class Texture")
        # First we check intersection with boundingBox
        if(self.get_prim() and self.get_absolute_points()):
            param_points_bounding_box = BoundingBox.BoundingBox2D(points, prim)
            texture_bounding_box = BoundingBox.BoundingBox2D(
                                                        self.get_absolute_points(),
                                                         self.get_prim())
            intersections = (
            texture_bounding_box.intersect_bounding_box_without_limits_3D(
            param_points_bounding_box))

            if (not intersections):
                return None, None, []
        else:
            if(not self.get_prim()):
                logging.debug("Class Texture, not prim in method check intersection with texture")
            else:
                logging.debug("No object points")
                logging.debug(str(self))
                logging.debug(str(self.get_is_default_texture()))
                logging.debug(str(self.get_absolute_points()))
                logging.debug(str(self.get_absolute_points_not_erasable()))
                logging.debug(str(self.get_delimited_proportions()))
                logging.debug(str(self.get_obj()))

        pointsIntersect = []
        for n in range(len(points) - 1):
            edge = [points[n], points[n + 1]]
            for texIndex in range(len(self.absolutePoints)):
                nextTexIndex = (texIndex + 1) % len(self.absolutePoints)
                texEdge = [self.absolutePoints[texIndex], self.absolutePoints[nextTexIndex]]
                pointIntersect = GeoMath.getFalseIntersectionBetweenTwoEdges3D(edge, texEdge, prim)
                # We have to avoid first point, that surely intersect with some texture.
                # Also avoid the case where two texture are together and pattern intersect with
                # the first texture, but when 'exit' from this texture, it intersect with the
                # other texture anda pattern of length 0 is used; with this method we avoid this
                if(pointIntersect):
                    distacenToLastPoint = GeoMath.vecModul(GeoMath.vecSub(
                                        points[len(points) - 1], pointIntersect))
                    if(GeoMath.vecModul(GeoMath.vecSub(pointIntersect, points[0]))
                        > epsilon and distacenToLastPoint > epsilon):
                        pointsIntersect.append(pointIntersect)

        if(pointsIntersect):
            nearestPointIntersect = None
            # Big number
            minDistance = 999999

            # For each point we look if intersection is the minimum distance intersection
            for pointIntersect in pointsIntersect:
                distance, achieved = GeoMath.takeDistanceInTrackToPoint(points,
                                                     pointIntersect, points[0])
                if(achieved and distance < minDistance and distance > epsilon):
                    # We need the minimun distance, but to avoid errors, we have
                    # to discard the first point and the last
                    minDistance = distance
                    nearestPointIntersect = pointIntersect

            if(not nearestPointIntersect):
                minDistance = None
        else:
            nearestPointIntersect = None
            minDistance = None

        if(nearestPointIntersect):
            logging.debug('End method checkIntersectionWithTexture,'
                          'class Texture. State: Intersection')
        else:
            logging.debug('End method checkIntersectionWithTexture,'
                          'class Texture. State: No intersection')

        return minDistance, nearestPointIntersect, pointsIntersect
开发者ID:csoriano89,项目名称:BuildingDestruction,代码行数:77,代码来源:Texture.py


注:本文中的lib.GeoMath.vecModul方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。