Ejemplo n.º 1
0
 def lineFaceSection(self, 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
         return 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
Ejemplo n.º 2
0
 def lineFaceSection(self,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
         return 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
Ejemplo n.º 3
0
def convertSection(section, x, z):
    """ Transform linear points distribution of full section 
    into double list, where points are gropued by height, and 
    reachs z maximum height.
    @param section Ship section.
    @param x Ship section x coordinate.
    @param z Maximum section height.
    @return Converted section, None if no valid section (i.e.- All section are over z)
    """
    # Convert into array with n elements (Number of points by sections)
    # with m elements into them (Number of points with the same height,
    # that is typical of multibody)
    points = []
    nPoints = 0
    j = 0
    while j < len(section) - 1:
        points.append([section[j]])
        k = j + 1
        last = False  # In order to identify if last point has been append
        while (k < len(section)):
            if not Math.isAprox(section[j].z, section[k].z):
                break
            points[nPoints].append(section[k])
            last = True
            k = k + 1
        nPoints = nPoints + 1
        j = k
    if not last:  # Last point has not been added
        points.append([section[len(section) - 1]])
    # Count the number of valid points
    n = 0
    for j in range(0, len(points)):
        Z = points[j][0].z
        if Z > z:
            break
        n = n + 1
    # Discard invalid sections
    if n == 0:
        return None
    # Truncate only valid points
    l = points[0:n]
    # Study if additional point is needed
    if n < len(points):
        # Get last sections
        pts1 = points[n]
        pts0 = points[n - 1]
        if len(pts1) == len(pts0):
            # Simple interpolation between points
            #    \----\-----|--------|
            #     \    |    |       /
            #      \    \   |      |
            #       \----|--|-----/
            pts = []
            for i in range(0, len(pts1)):
                y0 = pts0[i].y
                z0 = pts0[i].z
                y1 = pts1[i].y
                z1 = pts1[i].z
                factor = (z - z0) / (z1 - z0)
                y = y0 + factor * (y1 - y0)
                pts.append(App.Base.Vector(x, y, z))
            l.append(pts)
        if len(pts1) > len(pts0):
            # pts0 has been multiplied
            #    \---|---|
            #     \  |   |
            #      \ |   |
            #       \|---|
            # @todo Only katamaran are involved, multiple points multiplication must be study
            pts = []
            for i in range(0, len(pts1)):
                y0 = pts0[min(len(pts0) - 1, i)].y
                z0 = pts0[min(len(pts0) - 1, i)].z
                y1 = pts1[i].y
                z1 = pts1[i].z
                factor = (z - z0) / (z1 - z0)
                y = y0 + factor * (y1 - y0)
                pts.append(App.Base.Vector(x, y, z))
            l.append(pts)
        # @todo Only katamaran are involved, multiple points creation/destruction must be study
    return l
Ejemplo n.º 4
0
def convertSection(section, x, z):
    """ Transform linear points distribution of full section 
    into double list, where points are gropued by height, and 
    reachs z maximum height.
    @param section Ship section.
    @param x Ship section x coordinate.
    @param z Maximum section height.
    @return Converted section, None if no valid section (i.e.- All section are over z)
    """
    # Convert into array with n elements (Number of points by sections)
    # with m elements into them (Number of points with the same height,
    # that is typical of multibody)
    points = []
    nPoints = 0
    j = 0
    while j < len(section) - 1:
        points.append([section[j]])
        k = j + 1
        last = False  # In order to identify if last point has been append
        while k < len(section):
            if not Math.isAprox(section[j].z, section[k].z):
                break
            points[nPoints].append(section[k])
            last = True
            k = k + 1
        nPoints = nPoints + 1
        j = k
    if not last:  # Last point has not been added
        points.append([section[len(section) - 1]])
    # Count the number of valid points
    n = 0
    for j in range(0, len(points)):
        Z = points[j][0].z
        if Z > z:
            break
        n = n + 1
    # Discard invalid sections
    if n == 0:
        return None
    # Truncate only valid points
    l = points[0:n]
    # Study if additional point is needed
    if n < len(points):
        # Get last sections
        pts1 = points[n]
        pts0 = points[n - 1]
        if len(pts1) == len(pts0):
            # Simple interpolation between points
            #    \----\-----|--------|
            #     \    |    |       /
            #      \    \   |      |
            #       \----|--|-----/
            pts = []
            for i in range(0, len(pts1)):
                y0 = pts0[i].y
                z0 = pts0[i].z
                y1 = pts1[i].y
                z1 = pts1[i].z
                factor = (z - z0) / (z1 - z0)
                y = y0 + factor * (y1 - y0)
                pts.append(App.Base.Vector(x, y, z))
            l.append(pts)
        if len(pts1) > len(pts0):
            # pts0 has been multiplied
            #    \---|---|
            #     \  |   |
            #      \ |   |
            #       \|---|
            # @todo Only katamaran are involved, multiple points multiplication must be study
            pts = []
            for i in range(0, len(pts1)):
                y0 = pts0[min(len(pts0) - 1, i)].y
                z0 = pts0[min(len(pts0) - 1, i)].z
                y1 = pts1[i].y
                z1 = pts1[i].z
                factor = (z - z0) / (z1 - z0)
                y = y0 + factor * (y1 - y0)
                pts.append(App.Base.Vector(x, y, z))
            l.append(pts)
        # @todo Only katamaran are involved, multiple points creation/destruction must be study
    return l