def n_sided_patch(): # left pts1 = ( gp_Pnt(0, 0, 0.0), gp_Pnt(0, 1, 0.3), gp_Pnt(0, 2, -0.3), gp_Pnt(0, 3, 0.15), gp_Pnt(0, 4, 0), ) # front pts2 = ( gp_Pnt(0, 0, 0.0), gp_Pnt(1, 0, -0.3), gp_Pnt(2, 0, 0.15), gp_Pnt(3, 0, 0), gp_Pnt(4, 0, 0), ) # back pts3 = ( gp_Pnt(0, 4, 0), gp_Pnt(1, 4, 0.3), gp_Pnt(2, 4, -0.15), gp_Pnt(3, 4, 0), gp_Pnt(4, 4, 1), ) # right pts4 = ( gp_Pnt(4, 0, 0), gp_Pnt(4, 1, 0), gp_Pnt(4, 2, 0.3), gp_Pnt(4, 3, -0.15), gp_Pnt(4, 4, 1), ) spl1 = points_to_bspline(pts1) spl2 = points_to_bspline(pts2) spl3 = points_to_bspline(pts3) spl4 = points_to_bspline(pts4) edges = map(make_edge, [spl1, spl2, spl3, spl4]) verts = map(make_vertex, chain(pts1, pts2, pts3, pts4)) f1 = make_n_sided(edges, []) display.DisplayShape(edges) display.DisplayShape(verts) display.DisplayShape(f1, update=True)
def n_sided_patch(): # left pts1 = (gp_Pnt(0, 0, 0.0), gp_Pnt(0, 1, 0.3), gp_Pnt(0, 2, -0.3), gp_Pnt(0, 3, 0.15), gp_Pnt(0, 4, 0), ) # front pts2 = (gp_Pnt(0, 0, 0.0), gp_Pnt(1, 0, -0.3), gp_Pnt(2, 0, 0.15), gp_Pnt(3, 0, 0), gp_Pnt(4, 0, 0), ) # back pts3 = (gp_Pnt(0, 4, 0), gp_Pnt(1, 4, 0.3), gp_Pnt(2, 4, -0.15), gp_Pnt(3, 4, 0), gp_Pnt(4, 4, 1), ) # right pts4 = (gp_Pnt(4, 0, 0), gp_Pnt(4, 1, 0), gp_Pnt(4, 2, 0.3), gp_Pnt(4, 3, -0.15), gp_Pnt(4, 4, 1), ) spl1 = points_to_bspline(pts1) spl2 = points_to_bspline(pts2) spl3 = points_to_bspline(pts3) spl4 = points_to_bspline(pts4) edges = map(make_edge, [spl1, spl2, spl3, spl4]) verts = map(make_vertex, chain(pts1, pts2, pts3, pts4)) f1 = make_n_sided(edges, []) display.DisplayShape(edges) display.DisplayShape(verts) display.DisplayShape(f1, update=True)
def geodesic_path(pntA, pntB, edgA, edgB, kbe_face, n_segments=20, _tolerance=0.1, n_iter=20): """ :param pntA: point to start from :param pntB: point to move towards :param edgA: edge to start from :param edgB: edge to move towards :param kbe_face: kbe.face.Face on which `edgA` and `edgB` lie :param n_segments: the number of segments the geodesic is built from :param _tolerance: tolerance when the geodesic is converged :param n_iter: maximum number of iterations :return: TopoDS_Edge """ uvA, srf_pnt_A = kbe_face.project_vertex(pntA) uvB, srf_pnt_B = kbe_face.project_vertex(pntB) path = [] for i in range(n_segments): t = i / float(n_segments) u = uvA[0] + t * (uvB[0] - uvA[0]) v = uvA[1] + t * (uvB[1] - uvA[1]) path.append(kbe_face.parameter_to_point(u, v)) project_pnts = lambda x: [kbe_face.project_vertex(i)[1] for i in x] poly_length = lambda x: sum( [x[i].Distance(x[i + 1]) for i in range(len(x) - 1)]) / len(x) length = poly_length(path) n = 0 while True: path = smooth_pnts(path) path = project_pnts(path) newlength = poly_length(path) if abs(newlength - length) < _tolerance or n == n_iter: crv = points_to_bspline(path) return make_edge(crv) n += 1
def geodesic_path(pntA, pntB, edgA, edgB, kbe_face, n_segments=20, _tolerance=0.1, n_iter=20): """ :param pntA: point to start from :param pntB: point to move towards :param edgA: edge to start from :param edgB: edge to move towards :param kbe_face: kbe.face.Face on which `edgA` and `edgB` lie :param n_segments: the number of segments the geodesic is built from :param _tolerance: tolerance when the geodesic is converged :param n_iter: maximum number of iterations :return: TopoDS_Edge """ uvA, srf_pnt_A = kbe_face.project_vertex(pntA) uvB, srf_pnt_B = kbe_face.project_vertex(pntB) path = [] for i in range(n_segments): t = i / float(n_segments) u = uvA[0] + t*(uvB[0] - uvA[0]) v = uvA[1] + t*(uvB[1] - uvA[1]) path.append(kbe_face.parameter_to_point(u, v)) project_pnts = lambda x: [kbe_face.project_vertex(i)[1] for i in x] poly_length = lambda x: sum([x[i].Distance(x[i+1]) for i in range(len(x)-1)]) / len(x) length = poly_length(path) n = 0 while True: path = smooth_pnts(path) path = project_pnts(path) newlength = poly_length(path) if abs(newlength-length) < _tolerance or n == n_iter: crv = points_to_bspline(path) return make_edge(crv) n += 1