def xdraw_geodesics(geodesics, **kwargs): """Draw geodesic lines on specified surfaces, and optionally set individual name, color, arrow, and layer properties. """ guids = [] for g in iter(geodesics): sp = g['start'] ep = g['end'] srf = g['srf'] name = g.get('name', '') color = g.get('color') arrow = g.get('arrow') layer = g.get('layer') # replace this by a proper rhinocommon call guid = rs.ShortPath(srf, Point3d(*sp), Point3d(*ep)) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if arrow == 'end': attr.ObjectDecoration = EndArrowhead if arrow == 'start': attr.ObjectDecoration = StartArrowhead if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name obj.CommitChanges() guids.append(guid) return guids
points01 = rs.DivideCurveLength(curve01, length) points12 = rs.DivideCurveLength(curve12, length) points23 = rs.DivideCurveLength(curve23, length) points30 = rs.DivideCurveLength(curve30, length) m = (len(points12) + len(points30)) / 2 n = (len(points01) + len(points23)) / 2 points01 = rs.DivideCurve(curve01, n + 1) points12 = rs.DivideCurve(curve12, m + 1) points23 = rs.DivideCurve(curve23, n + 1) points30 = rs.DivideCurve(curve30, m + 1) m = int(m) n = int(n) bpoints = points01 + points12 + points23 + points30 for i in range(n): icurve = rs.ShortPath(surface, points01[i + 1], points23[-(i + 2)]) icurvesn.append(icurve) count = 0 while (count < loop): icurvesm = [] ipointssnm = [] for icurve in icurvesn: ipoints = rs.DivideCurve(icurve, m + 1) ipointssnm.append(ipoints) # global surfObj surfObj = rs.coercerhinoobject(surface).Geometry print surfObj for i in range(m): ps = [] puvs = [] p = points30[-(i + 1) - 1]
surface=surfaceToMesh(surface) print surface,type(surface) """ sortedCurves = [] bRing = False if bSquare: length01 = length length12 = length else: length01 = length / 2 length12 = length * 3**0.5 / 2 if len(curves) == 2: # 仅适用于单重曲面 addedCurves = [] if bFlip: rs.ReverseCurve(curves[1]) curve12 = rs.ShortPath(surface, rs.CurveEndPoint(curves[0]), rs.CurveStartPoint(curves[1])) curve30 = rs.ShortPath(surface, rs.CurveEndPoint(curves[1]), rs.CurveStartPoint(curves[0])) sortedCurves = [curves[0], curve12, curves[1], curve30] if len(curves) == 4 or len(curves) == 3: if bSortCurves: sortedCurves = SortCurves(curves) else: sortedCurves = curves if bLength and length: m = round( (rs.CurveLength(sortedCurves[1]) + rs.CurveLength(sortedCurves[3])) / length12 / 2) - 1 n = round( (rs.CurveLength(sortedCurves[0]) + rs.CurveLength(sortedCurves[2])) / length01 / 2) - 1
def InterporateCurves(surface, curves, m, n, loop, bAdaptive, bRatio, bRing=False): """在两个方向上分别生成m,n条生成插值曲线""" bEdgeBePoint = False m = int(m) n = int(n) icurvesn = [] icurvesm = [] ipointssnm = [] ipointssmn = [] if len(curves) == 4: curve01 = curves[0] curve12 = curves[1] curve23 = curves[2] curve30 = curves[3] if len(curves) == 3: curve01 = curves[0] curve12 = curves[1] curve23 = rs.CurveEndPoint(curves[1]) curve30 = curves[2] rm = 1 rn = 1 # print len(curves) if bRatio: rm = (rs.CurveLength(curve23) / rs.CurveLength(curve01))**(1 / (m)) # rn=1 rn = (rs.CurveLength(curve30) / rs.CurveLength(curve12))**(1 / (n)) points01 = DivideCurveByNumberAndRatio(curve01, n + 1, 1 / rn) points12 = DivideCurveByNumberAndRatio(curve12, m + 1, rm) if len(curves) == 4: points23 = DivideCurveByNumberAndRatio(curve23, n + 1, rn) global points000 points000 = points23[:] if len(curves) == 3: points23 = [curve23] * (n + 2) points30 = DivideCurveByNumberAndRatio(curve30, m + 1, 1 / rm) # print "points01",points01 # print "points23",points23 # if bRing: # points23=ghc.ShiftList(points23,1,True) # if rs.IsCurveClosed(curve23)and rs.IsCurveClosed(curve30): # points30=ghc.ShiftList(points30,1,True) bpoints = points01 + points12 + points23 + points30 if bRing: points23 = ghc.ShiftList(points23, 1, True) for i in range(n): if (rs.IsSurface(surface)): icurve = rs.ShortPath(surface, points01[i + 1], points23[::-1][i + 1]) else: icurve = rs.AddLine(points01[i + 1], points23[::-1][i + 1]) icurvesn.append(icurve) count = 0 ipointss = [] while (count < loop): # 完整的一次循环,count=+2 ipointssnm = [] ipointssnm = [] relativeLengths = [] if (bAdaptive and count != 0): curvesm = icurvesm[:] curvesm.insert(0, curve01) curvesm.append(curve23) sumMidLength = 0 midLengths = [] for ii in range(m + 1): midLength = (rs.CurveLength(curvesm[ii]) + rs.CurveLength(curvesm[ii + 1])) * 0.5 midLengths.append(midLength) sumMidLength += midLength relativeLengths = [ midLength / sumMidLength for midLength in midLengths ] points12 = DivideCurveByRelativeLengths(curve12, relativeLengths) points30 = DivideCurveByRelativeLengths( curve30, list(reversed(relativeLengths))) for icurve in icurvesn: if (bAdaptive and count != 0): # print "relativeLengths1",relativeLengths ipoints = DivideCurveByRelativeLengths(icurve, relativeLengths) else: ipoints = DivideCurveByNumberAndRatio(icurve, m + 1, rm) ipointssnm.append(ipoints) # global surfObj surfObj = rs.coercerhinoobject(surface).Geometry # print surfObj icurvesm = [] for i in range(m): if (rs.IsSurface(surface)): puvs = [] p = points30[-(i + 1) - 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) for j in range(n): # 转换数据类型 p = ipointssnm[j][i + 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) if not bRing: p = points12[i + 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) # print (count) # print (puvs[2]) crv = ghc.CurveOnSurface(surfObj, puvs, bRing)[0] icurvesm.append(crv) else: ps = [] p = points30[-(i + 1) - 1] ps.append(p) for j in range(n): # 转换数据类型 p = ipointssnm[j][i + 1] pm = rs.MeshClosestPoint(surface, p)[0] ps.append(pm) # points12和points03的节点位置可能不完全重合,曲线的朝向影响了分段结果 if not bRing: p = points12[i + 1] else: p = points30[-(i + 1) - 1] ps.append(p) crv = rs.AddPolyline(ps) # print rs.IsCurveClosed(crv) icurvesm.append(crv) count = count + 1 points03 = list(reversed(points30)) ipointss = ipointssnm ipointss.insert(0, points03) if not bRing: ipointss.append(points12) if (count >= loop): print('循环正常结束') break ipointssmn = [] relativeLengths = [] if (bAdaptive and count != 0): curvesn = icurvesn[:] curvesn.insert(0, curve30) curvesn.append(curve12) sumMidLength = 0 midLengths = [] for ii in range(n + 1): midLength = (rs.CurveLength(curvesn[ii]) + rs.CurveLength(curvesn[ii + 1])) * 0.5 midLengths.append(midLength) sumMidLength += midLength # print "midLengths",midLengths relativeLengths = [ midLength / sumMidLength for midLength in midLengths ] points01 = DivideCurveByRelativeLengths(curve01, relativeLengths) points23 = DivideCurveByRelativeLengths( curve23, list(reversed(relativeLengths))) if rs.IsCurveClosed(curve23): points23 = ghc.ShiftList(points23, 1, True) for icurve in icurvesm: if (bAdaptive and count != 0): # print "relativeLengths2",relativeLengths ipoints = DivideCurveByRelativeLengths(icurve, relativeLengths) else: ipoints = DivideCurveByNumberAndRatio(icurve, n + 1, 1 / rn) # print n+1,1/rn,rs.IsCurveClosed(icurve) # print "ipoints",len(ipoints) ipointssmn.append(ipoints) icurvesn = [] # global surfObj surfObj = rs.coercerhinoobject(surface).Geometry # print surfObj for i in range(n): if (rs.IsSurface(surface)): ps = [] puvs = [] p = points01[(i + 1)] ps.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) for j in range(m): # 转换数据类型 p = ipointssmn[j][i + 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) p = points23[-(i + 1) - 1] ps.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) crv = ghc.CurveOnSurface(surfObj, puvs, False)[0] crvm = rs.AddPolyline(ps) icurvesn.append(crv) else: ps = [] p = points01[(i + 1)] ps.append(p) for j in range(m): # 转换数据类型 p = ipointssmn[j][i + 1] pm = rs.MeshClosestPoint(surface, p)[0] ps.append(pm) p = points23[-(i + 1) - 1] ps.append(p) crv = rs.AddPolyline(ps) icurvesn.append(crv) count = count + 1 ipointss = ipointssmn points32 = list(reversed(points23)) ipointss.insert(0, points01) ipointss.append(points32) # print count,len(ipointss[0]),len(ipointss[1]),len(ipointss[2]),len(ipointss[3]) if (count >= 100): break # print "ipointss",ipointss return icurvesm, icurvesn, ipointss
def draw_geodesics(geodesics, **kwargs): """Draw geodesic lines on specified surfaces, and optionally set individual name, color, arrow, and layer properties. Parameters ---------- labels : list of dict A list of geodesic dictionaries. Returns ------- list of GUID Notes ----- A geodesic dict has the following schema: .. code-block:: python Schema({ 'start': And(list, lambda x: len(x) == 3), 'end': And(list, lambda x: len(x) == 3), 'srf': Or(str, System.Guid), Optional('name', default=''): str, Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)), Optional('layer', default=None): str, Optional('arrow', default=None): str, }) """ guids = [] for g in iter(geodesics): sp = g['start'] ep = g['end'] srf = g['srf'] name = g.get('name', '') color = g.get('color') arrow = g.get('arrow') layer = g.get('layer') # replace this by a proper rhinocommon call guid = rs.ShortPath(srf, Point3d(*sp), Point3d(*ep)) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if arrow == 'end': attr.ObjectDecoration = EndArrowhead if arrow == 'start': attr.ObjectDecoration = StartArrowhead if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name obj.CommitChanges() guids.append(guid) return guids