예제 #1
0
파일: Geometry.py 프로젝트: archri/freecad
def lineFaceSection(line, surface):
    """ Returns the point of section of a line with a face
    @param line Line object, that can be a curve.
    @param surface Surface object (must be a Part::Shape)
    @return Section points array, [] if line don't cut surface
    """
    # Get initial data
    result = []
    vertexes = line.Vertexes
    nVertex = len(vertexes)
    # Perform the cut
    section = line.cut(surface)
    # Filter all old points
    points = section.Vertexes
    nPoint = len(points)
    if nPoint <= nVertex:
        # Any valid point
        result
    for i in range(0, nPoint):
        disp = len(result)
        flag = 0
        if not Math.isAprox(points[i].X, vertexes[i - disp].X, 0.0001):
            flag = flag + 1
        if not Math.isAprox(points[i].Y, vertexes[i - disp].Y, 0.0001):
            flag = flag + 1
        if not Math.isAprox(points[i].Z, vertexes[i - disp].Z, 0.0001):
            flag = flag + 1
        if flag > 0:
            result.append(points[i])
    return result
예제 #2
0
 def sortEdges(self):
     """ Sort the edges by their connection points. Also gives if
     an edge is ill oriented (thir connection point is the end
     point, not the starting point), with True when is good oriented,
     and False otherwise.
     @return True if error happens. False otherwise
     """
     edges = self.edges
     self.edges = [edges[0]]
     self.direction = [True]
     Vertex = self.edges[0].Vertexes[1]
     for i in range(0,len(edges)-1):
         for j in range(0,len(edges)):
             if self.edges[i] == edges[j]:
                 continue
             Vertexes = edges[j].Vertexes
             if Math.isSameVertex(Vertex,Vertexes[0]):
                 Vertex = Vertexes[1]
                 self.edges.append(edges[j])
                 self.direction.append(True)
                 break
             if Math.isSameVertex(Vertex,Vertexes[1]):
                 Vertex = Vertexes[0]
                 self.edges.append(edges[j])
                 self.direction.append(False)
                 break
     return False
예제 #3
0
def lineFaceSection(line, surface):
    """ Returns the point of section of a line with a face
    @param line Line object, that can be a curve.
    @param surface Surface object (must be a Part::Shape)
    @return Section points array, [] if line don't cut surface
    """
    # Get initial data
    result = []
    vertexes = line.Vertexes
    nVertex = len(vertexes)
    # Perform the cut
    section = line.cut(surface)
    # Filter all old points
    points = section.Vertexes
    nPoint = len(points)
    if nPoint <= nVertex:
        # Any valid point
        result
    for i in range(0, nPoint):
        disp = len(result)
        flag = 0
        if not Math.isAprox(points[i].X, vertexes[i - disp].X, 0.0001):
            flag = flag + 1
        if not Math.isAprox(points[i].Y, vertexes[i - disp].Y, 0.0001):
            flag = flag + 1
        if not Math.isAprox(points[i].Z, vertexes[i - disp].Z, 0.0001):
            flag = flag + 1
        if flag > 0:
            result.append(points[i])
    return result
예제 #4
0
 def isClosed(self):
     """ Returns if the edges objects are a closed curve.
     @return True if a closed curve can be built with edge objects.
     False otherwise
     """
     edges = self.edges
     for i in range(0,len(edges)):
         edge = edges[i]
         vertex1 = edge.Vertexes
         count = [0,0]
         for j in range(0,len(edges)):
             if j== i:
                 continue
             vertex2 = edges[j].Vertexes
             for k in range(0,2):
                 if Math.isSameVertex(vertex1[0],vertex2[k]):
                     count[0] = count[0]+1
                 if Math.isSameVertex(vertex1[1],vertex2[k]):
                     count[1] = count[1]+1
         if count != [1,1]:
             msg = Translator.translate("4 Edges curve must be closed")
             App.Console.PrintError(msg)
             return False
     return True