Exemplo n.º 1
0
 def splitBranch(self,branch, point):
     self.points.append(point)
     radius = branch.radius
     new = Branch(len(self.points)-1, branch.finalPoint, radius)
     new.root = branch
     new.son1 = branch.son1
     new.son2 = branch.son2
     if branch.son1 is not None:
         new.son1.root = new
     if branch.son2 is not None:
         new.son2.root = new
         branch.son2 = None 
     branch.finalPoint = new.initialPoint
     branch.son1 = new
Exemplo n.º 2
0
    def bif(self, branch):
        pi = self.points[branch.initialPoint]
        pf = self.points[branch.finalPoint]
        pi1 = self.points[branch.son1.initialPoint]
        pf1 = self.points[branch.son1.finalPoint]
        pi2 = self.points[branch.son2.initialPoint]
        pf2 = self.points[branch.son2.finalPoint]
        lenght = geo.distance(pi, pf)
            
        t=(lenght-1.1*branch.radius)/lenght
        newPf = [(1-t)*pi[0]+t*pf[0],((1-t)*pi[1]+t*pf[1]),((1-t)*pi[2]+t*pf[2])]
        self.points[branch.finalPoint] = newPf
        #geo.createVertex(newPf[0],newPf[1],newPf[2])
        t=(lenght+0*branch.radius)/lenght
        newPoint1 = [(1-t)*pi[0]+t*pf[0],((1-t)*pi[1]+t*pf[1]),((1-t)*pi[2]+t*pf[2])]
#         u0 = [newPf[0]-newPoint1[0],newPf[1]-newPoint1[1],newPf[2]-newPoint1[2]]
#         u1 = [newPoint1[0]-pf1[0],newPoint1[1]-pf1[1],newPoint1[2]-pf1[2]]
#         u0 = [newPoint1[0]-newPf[0],newPoint1[1]-newPf[1],newPoint1[2]-newPf[2]]
#         u1 = [pf1[0]-newPf[0],pf1[1]-newPf[1],pf1[2]-newPf[2]]
        u0 = [pf1[0]-newPf[0],pf1[1]-newPf[1],pf1[2]-newPf[2]]
        u1 = [pf2[0]-newPf[0],pf2[1]-newPf[1],pf2[2]-newPf[2]]
        u = geo2.crossProduct(u0, u1)
        u = geo2.getVector4_3(u)
        geo2.normalizeVector(u)
        newPoint1 = geo2.rotateByAxis(geo2.getVector4_3(newPoint1), geo2.getVector4_3(newPf), u, 40)
        vecR = geo2.getVector(pi, newPf)
        vecF1 = geo2.getVector(newPf, newPoint1)
        #geo.createVertex(newPoint1[0],newPoint1[1],newPoint1[2])
        t=(lenght+0*branch.radius)/lenght
        newPoint2 = [(1-t)*pi[0]+t*pf[0],((1-t)*pi[1]+t*pf[1]),((1-t)*pi[2]+t*pf[2])]
#         u0 = [newPoint2[0]-newPf[0],newPoint2[1]-newPf[1],newPoint2[2]-newPf[2]]
#         u1 = [pf2[0]-newPf[0],pf2[1]-newPf[1],pf2[2]-newPf[2]]
#         u = geo2.crossProduct(u0, u1)
#         u = geo2.getVector4_3(u)
#         geo2.normalizeVector(u)
        newPoint2 = geo2.rotateByAxis(geo2.getVector4_3(newPoint2), geo2.getVector4_3(newPf), u, -40)
        vecF2 = geo2.getVector(newPf, newPoint2)
        ang3 = geo2.getAngle(vecF1, vecF2)
        if ang3 < 60:
            newPoint1 = geo2.rotateByAxis(geo2.getVector4_3(newPoint1), geo2.getVector4_3(newPf), u, 20)
            newPoint2 = geo2.rotateByAxis(geo2.getVector4_3(newPoint2), geo2.getVector4_3(newPf), u, -20)
        #geo.createVertex(newPoint2[0],newPoint2[1],newPoint2[2])
        d1 = geo.distance(pf1, newPoint1)+geo.distance(pf2, newPoint2)
        d2 = geo.distance(pf1, newPoint2)+geo.distance(pf2, newPoint1)
        if d1>d2:
            aux = newPoint1
            newPoint1 = newPoint2
            newPoint2 = aux
        self.points.append(newPoint1)
        radius1 = branch.radius
        radius2 = branch.radius
#         radius1 = branch.son1.radius
#         radius2 = branch.son2.radius
#         sumRadius = radius1 + radius2
#         while sumRadius > 1.2:
#             radius1 = radius1*0.95
#             radius2 = radius2*0.95
#             sumRadius = radius1 + radius2
        new1 = Branch(branch.finalPoint, len(self.points)-1,radius1)
        new1.root = branch
        new1.son1 = branch.son1
        new1.son1.initialPoint = len(self.points)-1
        new1.son1.root = new1
        branch.son1 = new1
           
        self.points.append(newPoint2)
        new2 = Branch(branch.finalPoint, len(self.points)-1, radius2)
        new2.root = branch
        new2.son1 = branch.son2
        new2.son1.initialPoint = len(self.points)-1
        new2.son1.root = new2
        branch.son2 = new2