コード例 #1
0
ファイル: RSTurtle.py プロジェクト: alireza116/RSTurtle
 def grid(self, sqr, x, y):
     xpldCrv = rs.ExplodeCurves(sqr)
     rs.ReverseCurve(xpldCrv[0])
     rs.ReverseCurve(xpldCrv[3])
     crvPoints = []
     for i in range(len(xpldCrv)):
         curve = xpldCrv[i]
         if i % 2 == 0:
             crvPoints.append(rs.DivideCurve(curve, x))
         else:
             crvPoints.append(rs.DivideCurve(curve, y))
         #divide up the curve into points based on x and y
         #add the resulting points to the curvePoints List. Each of the resulting points sets are a list themsleves
     for p1, p2 in zip(crvPoints[0], crvPoints[2]):
         #draw a line between p1, p2
         print(p1)
         #rs.AddLine(p1,p2)
         self.penUp()
         self.goto(p1[0], p1[1], p1[2])
         self.penDown()
         self.goto(p2[0], p2[1], p2[2])
     for p1, p2 in zip(crvPoints[1], crvPoints[3]):
         self.penUp()
         l = self.goto(p1[0], p1[1], p1[2])
         self.penDown()
         self.goto(p2[0], p2[1], p2[2])
コード例 #2
0
 def getExtendedCrv(self, crvList, dist=50, layer_height=2.5, vecMul=.66):
     segmentCount = int(math.floor(dist / layer_height)) - 1
     tmpList = []
     fullHeight = []
     for i in range(len(crvList)):
         extendedCrv = rs.ExtendCurveLength(crvList[i], 2, 0, dist)
         fullHeight.append(extendedCrv)
         domStart, domEnd = rs.CurveDomain(extendedCrv)
         trimmedCrv = rs.TrimCurve(extendedCrv, (domStart, 0))
         tmpList.append(trimmedCrv)
     tmp = []
     ###Smooth Curves###
     for i in range(len(tmpList)):
         bottomPt = rs.CurveEndPoint(tmpList[i])
         zVec = rs.VectorAdd((0, 0, 0), (0, 0, dist))
         topPt = rs.CopyObject(bottomPt, zVec)
         line = rs.AddLine(bottomPt, topPt)
         crvPts = rs.DivideCurve(tmpList[i], segmentCount)
         LinePts = rs.DivideCurve(line, segmentCount)
         for i in range(segmentCount):
             tmpVec = rs.VectorCreate(LinePts[segmentCount - i - 1],
                                      crvPts[i])
             tmpVec = rs.VectorScale(tmpVec, vecMul)
             rs.MoveObject(crvPts[i], tmpVec)
         tmp.append(rs.AddInterpCurve(crvPts))
         result = []
         for crv in tmp:
             crvLen = rs.CurveLength(crv)
             if crvLen < dist:
                 tmpExt = dist - crvLen
                 result.append(rs.ExtendCurveLength(crv, 2, 0, tmpExt))
             else:
                 result.append(rs.CopyObject(crv))
     return result
コード例 #3
0
def Previewmark(crvs, dict, index):# 線の目印を作る
	pt_o = rs.DivideCurve(crvs[dict[index][0]], 10)
	pt_x = rs.DivideCurve(crvs[dict[index][1]], 10)
	mark_o = [rs.AddCircle(cen, mark) for cen in pt_o]
	mark_x1 = [rs.AddLine((cen[0] - mark,cen[1],cen[2]), (cen[0] + mark,cen[1],cen[2])) for cen in pt_x]
	mark_x2 = [rs.AddLine((cen[0],cen[1] - mark,cen[2]), (cen[0],cen[1] + mark,cen[2])) for cen in pt_x]
	a = mark_o
	b = mark_x1 + mark_x2
	return (a, b)
コード例 #4
0
def squareSect(crv,width,height):
    sections=[]
    divPts=rs.DivideCurve(crv,10)
    keep=True
    for i in range(len(divPts)):
        param=rs.CurveClosestPoint(crv,divPts[i])
        tan=rs.CurveTangent(crv,param)
        plane=rs.PlaneFromNormal(divPts[i],tan)
        sect=rs.AddRectangle(plane,width,height)
        cpt=rs.CurveAreaCentroid(sect)[0]
        vec=rs.VectorCreate(divPts[i],cpt)
        sect=rs.MoveObject(sect,vec)
        if i>0:
            if testAlign(sect,oldSect)==False:
                sect=align(sect,oldSect,divPts[i],tan)
        oldSect=sect
        sections.append(sect)
    branch=rs.AddLoftSrf(sections,None,None,2,0,0,False)
    edges=rs.DuplicateEdgeCurves(branch)
    if width>height:
        testVal=height
    else:
        testVal=width
    for i in range(len(edges)):
        testPt=rs.CurveMidPoint(edges[i])
        for j in range(len(edges)):
            param=rs.CurveClosestPoint(edges[j],testPt)
            pt=rs.EvaluateCurve(edges[j],param)
            if rs.Distance(pt,testPt)<testVal/6:
                keep=False
    rs.DeleteObjects(sections)
    rs.DeleteObjects(edges)
    return branch
コード例 #5
0
def addJoin(lns, nJoins, xThick, yThick):

    joins = []
    joins_3 = []

    points = rs.DivideCurve(lns, nJoins)
    lenP = len(points)

    for i in range(lenP):
        joins.append(rs.AddPoint(points[i]))

    joins_2 = rs.CopyObjects(joins, [xThick, yThick, 0])
    joins_2.remove(joins_2[0])
    joins_2.append([0, 0, 0])

    for j in range(0, len(joins), 2):
        c = j + 2
        addList(joins, joins_2, joins_3, j, c)

    joins_3.remove(joins_3[len(joins_3) - 1])
    joins_3.remove(joins_3[len(joins_3) - 1])
    joined = rs.AddPolyline(joins_3)
    rs.DeleteObject(lns)

    return joined
コード例 #6
0
def centerCrv(crv):
    sum = [0, 0, 0]
    pts = rs.DivideCurve(crv, 1000)
    for i in range(len(pts)):
        sum = rs.PointAdd(sum, pts[i])
    cnt = sum / len(pts)
    return cnt
コード例 #7
0
def depressCrvs(crvs, paths, startPt, radius, sd):
    newCrvs = []
    for i in range(len(crvs)):
        divPts = rs.DivideCurve(crvs[i], 100)
        if i < len(crvs) - 1:
            cntPt01 = centerCrv(crvs[i])
            cntPt02 = centerCrv(crvs[i + 1])
            horVec = rs.VectorCreate(cntPt01, cntPt02)
        for j in range(len(divPts)):
            path = rs.PointClosestObject(divPts[j], paths)[0]
            param = rs.CurveClosestPoint(path, divPts[j])
            close = rs.EvaluateCurve(path, param)
            dist = rs.Distance(close, divPts[j])
            tan = rs.CurveTangent(crvs[i], param)
            vec = [0, 0, -1]  #rs.VectorCrossProduct(horVec,tan)
            testVec = rs.VectorCreate(cntPt01, divPts[j])
            if rs.VectorDotProduct(vec, testVec) < 0:
                rs.VectorReverse(vec)
            vec = rs.VectorUnitize(vec)
            border = 1
            entry = 1
            if j > len(divPts) / 2:
                border = rs.Distance(rs.CurveEndPoint(crvs[i]), divPts[j])
            else:
                border = rs.Distance(rs.CurveStartPoint(crvs[i]), divPts[j])
            if border < sd * 3:
                border = border / (sd * 3)
            entryDist = rs.Distance(startPt, divPts[j])
            if entryDist < sd * 10:
                entry = entryDist / (sd * 10)
            if dist < sd * 2:
                val = radius * (bellCrv(dist, sd))
                divPts[j] = rs.PointAdd(divPts[j], vec * val * border * entry)
        newCrvs.append(rs.AddCurve(divPts))
    return divPts
コード例 #8
0
def surface_discrete_mapping(srf_guid, discretisation, minimum_discretisation = 5, crv_guids = [], pt_guids = []):
	"""Map the boundaries of a Rhino NURBS surface to planar poylines dicretised within some discretisation using the surface UV parameterisation.
	Curve and point feautres on the surface can be included.
	Parameters
	----------
	srf_guid : guid
		A surface guid.
	crv_guids : list
		List of guids of curves on the surface.
	pt_guids : list
		List of guids of points on the surface.
	discretisation : float
		The discretisation of the surface boundaries.
	minimum_discretisation : int
		The minimum discretisation of the surface boundaries.
	Returns
	-------
	tuple
		Tuple of the mapped objects: outer boundary, inner boundaries, polyline_features, point_features.
	"""

	srf = RhinoSurface.from_guid(srf_guid)

	# a boundary may be made of multiple boundary components and therefore checking for closeness and joining are necessary
	mapped_borders = []

	for i in [1, 2]:
		mapped_border = []

		for border_guid in srf.borders(type = i):
			points = [list(srf.point_xyz_to_uv(pt)) + [0.0] for pt in rs.DivideCurve(border_guid, max(int(rs.CurveLength(border_guid) / discretisation) + 1, minimum_discretisation))]
			
			if rs.IsCurveClosed(border_guid):
				points.append(points[0])
			
			mapped_border.append(points)
			rs.DeleteObject(border_guid)
		mapped_borders.append(mapped_border)

	outer_boundaries, inner_boundaries = [network_polylines(Network.from_lines([(u, v) for border in mapped_borders[i] for u, v in pairwise(border)])) for i in [0, 1]]
	
	# mapping of the curve features on the surface
	mapped_curves = []

	for crv_guid in crv_guids:

		curve = RhinoCurve.from_guid(crv_guid)
		points = [list(srf.point_xyz_to_uv(pt)) + [0.0] for pt in curve.divide(max(int(curve.length() / discretisation) + 1, minimum_discretisation))]
		
		if curve.is_closed():
			points.append(points[0])
		
		mapped_curves.append(points)

	polyline_features = network_polylines(Network.from_lines([(u, v) for curve in mapped_curves for u, v in pairwise(curve)]))

	# mapping of the point features onthe surface
	point_features = [list(srf.point_xyz_to_uv(rs.PointCoordinates(pt_guid))) + [0.0] for pt_guid in pt_guids]

	return outer_boundaries[0], inner_boundaries, polyline_features, point_features
コード例 #9
0
def create_targets(mesh, targets, resolution_mult, path, folder_name,
                   json_name):
    """ Creation of targets for curved slicing. """

    avg_face_area = max(rs.MeshArea([mesh])) / rs.MeshFaceCount(mesh)
    div_num = max(20, int(resolution_mult * avg_face_area))

    pts = []
    for target in targets:
        print(div_num)
        pts.extend(rs.DivideCurve(target, div_num))

    vs = rs.MeshVertices(mesh)
    vertices = []
    vertex_indices = []
    for p in pts:
        closest_vi = get_closest_point_index(p, vs)
        if closest_vi not in vertex_indices:
            ds_from_targets = [
                distance_of_pt_from_crv(vs[closest_vi], target)
                for target in targets
            ]
            if min(ds_from_targets) < 0.5:  # hardcoded threshold value
                vertices.append(vs[closest_vi])
                vertex_indices.append(closest_vi)

    save_json_file(vertex_indices, path, folder_name, json_name)
    return pts, vertices, vertex_indices
コード例 #10
0
def depressCrvs(srf, crvs, paths, startPt, radius, sd):
    newCrvs = []
    for i in range(len(crvs)):
        divPts = rs.DivideCurve(crvs[i], 400)
        for j in range(len(divPts)):
            path = rs.PointClosestObject(divPts[j], paths)[0]
            param = rs.CurveClosestPoint(path, divPts[j])
            close = rs.EvaluateCurve(path, param)
            srfParam = rs.SurfaceClosestPoint(srf, close)
            vec = rs.SurfaceNormal(srf, srfParam)
            dist = rs.Distance(close, divPts[j])
            vec = rs.VectorUnitize(vec)
            border = 1
            entry = 1
            if j > len(divPts) / 2:
                border = rs.Distance(rs.CurveEndPoint(crvs[i]), divPts[j])
            else:
                border = rs.Distance(rs.CurveStartPoint(crvs[i]), divPts[j])
            if border < sd * 3:
                border = border / (sd * 3)
            else:
                border = 1
            entryDist = rs.Distance(startPt, divPts[j])
            if entryDist < sd * 10:
                entry = entryDist / (sd * 10)
            else:
                entry = 1
            if dist < sd * 2:
                val = radius * (bellCrv(dist, sd))
                divPts[j] = rs.PointAdd(divPts[j], vec * val * border * entry)
        newCrvs.append(rs.AddCurve(divPts))
    return divPts
コード例 #11
0
def ColorObjsRandomRange():
    try:
        objs = rs.GetObjects("Select objects to color",
                             1073750077,
                             preselect=True)
        if objs is None: return
        print "Select First Color"
        firstColor = rs.GetColor()
        if firstColor is None: return
        print "Select Second Color"
        secondColor = rs.GetColor(firstColor)
        if secondColor is None: return

        rs.EnableRedraw(False)
        colorLine = rs.AddLine(firstColor, secondColor)

        try:
            colors = rs.DivideCurve(colorLine, len(objs) - 1)

            shuffle(colors)

            for i, obj in enumerate(objs):
                rs.ObjectColor(obj, (colors[i].X, colors[i].Y, colors[i].Z))
        except:
            pass
        rs.DeleteObject(colorLine)
        rs.EnableRedraw(True)
        return True
    except:
        return False
コード例 #12
0
def tweenCurveOnsurface(m, n, icurves, points0, points1):
    print {'def'}
    print {m}
    for icurve in icurves:
        ipoints = rs.DivideCurve(icurve, m + 1)
        ipointssnm.append(ipoints)
    for i in range(m):
        icurvesNew = []
        ps = []
        puvs = []
        p = points1[(i + 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]
            ps.append(p)
            puvs.append(puv)
        p = points0[i + 1]
        puv = ghc.SurfaceClosestPoint(p, surfObj)[1]
        puvs.append(puv)
        crv = ghc.CurveOnSurface(surfObj, puvs, False)[0]
        icurvesNew.append(crv)
        print(crv)
    return icurvesNew
コード例 #13
0
def find_devisions(mesh, edge_groups, trg_len):

    for edges in edge_groups:

        lengths = 0
        for u, v in edges:
            lengths += mesh.get_edge_attribute((u, v), 'length')

            ave_len = lengths / len(edges)
            div = max((round(ave_len / trg_len, 0), 1))

        for u, v in edges:
            crv = mesh.get_edge_attribute((u, v), 'guid')
            pts = rs.DivideCurve(crv, div)
            mesh.set_edge_attribute((u, v), 'points', pts)

    edges = set(mesh.edges())
    coons_meshes = []

    for fkey in mesh.faces():

        if mesh.get_face_attribute(fkey, 'opening'):
            continue

        h_edges = mesh.face_halfedges(fkey)

        # arrange point lists in circular order along edge faces
        pts_coon = []
        for h_edge in h_edges:
            pts = mesh.get_edge_attribute(h_edge, 'points')[:]
            if not h_edge in edges:
                pts.reverse()
            if not mesh.get_edge_attribute(h_edge, 'dir'):
                pts.reverse()
            pts_coon.append(pts)

        # handle triangles correctly based on user input (flag 0 - 2)
        if len(h_edges) == 4:
            ab, bc, dc, ad = pts_coon
        else:
            flag = mesh.get_face_attribute(fkey, 'corner')
            if flag == 0:
                ab, bc, dc, ad = pts_coon[0], pts_coon[1], [], pts_coon[2]
            elif flag == 1:
                ab, bc, dc, ad = pts_coon[0], [], pts_coon[1], pts_coon[2]
            elif flag == 2:
                ab, bc, dc, ad = pts_coon[0], pts_coon[1], pts_coon[2], []

        # reverse for coons patch (see parameters)
        dc.reverse()
        ad.reverse()

        try:  #this try except is a bit of a hack to make the openings work (needs revision)
            vertices, faces = discrete_coons_patch(ab, bc, dc, ad)
            coons_meshes.append(Mesh.from_vertices_and_faces(vertices, faces))
        except:
            pass

    return coons_meshes
コード例 #14
0
 def crv2pts(self, crvList, startLayer=1):
     result = []
     print(self.resolution, len(crvList))
     for i in range(startLayer, len(crvList)):
         pts = rs.DivideCurve(crvList[i], self.resolution)
         result.extend(pts)
     print(len(result))
     return result
コード例 #15
0
ファイル: rsTools.py プロジェクト: vctcn93/rhinoscript
def divEQCrvToPolyAD(crv,w=900,adjacentCrvs=None):
    outpoly=PolyAD()
    crvLen=rs.CurveLength(crv)
    numDiv=crvLen/w
    width=crvLen/round(numDiv)
    pts=rs.DivideCurve(crv,numDiv,False,True)
        #add to output
    outpoly.points=pts

    sharedNormals=[None,None]
    if adjacentCrvs is not None:
        sharedNormals=findSharedbisecNormals(crv,adjacentCrvs)


    for i in range(0,len(pts)-2):
        up=(0,0,1)

        #     direct   direct_end
        # (p0)-v1->(p1)-v2->(p2)
        #   |n_start |n      |n_end
        #   V        V       V

        p0=pts[i]
        p1=pts[i+1]
        p2=pts[i+2]

        v1=rs.VectorUnitize(p1-p0)
        v2=rs.VectorUnitize(p2-p1)
        n1=rs.VectorCrossProduct(v1,up)
        n2=rs.VectorCrossProduct(v2,up)
        mid=rs.VectorAdd(n1,n2)
        n=rs.VectorUnitize(mid)

        direct=p1-p0
        #add to output
        outpoly.directions.append(direct)

        if i==0:
            if sharedNormals[0] is not None: n_start=sharedNormals[0]

            else: n_start=rs.VectorCrossProduct(v1,up)
            outpoly.normals.append(n_start)

        #add to output
        outpoly.normals.append(n)

        if i==len(pts)-3:
            if sharedNormals[1] is not None: n_end=sharedNormals[1]
            else: n_end=rs.VectorCrossProduct(v2,up)
            outpoly.normals.append(n_end)
            direct_end=p2-p1
            outpoly.directions.append(direct_end)




    return outpoly
コード例 #16
0
def main():
    surface_id = rs.GetObject("Select a surface to sample", 8, True)#select surface
    if not surface_id: return #if not surface, it will not continue
    curve_id = rs.GetObject("Select a curve to measure", 4, True, True)#select curve
    if not curve_id: return #if not curve, it will not continue
    points = rs.DivideCurve(curve_id, 500) #divide curve in 500 Segments
    rs.EnableRedraw(False)
    for point in points: evaluatedeviation(surface_id, 5.0, point)#calls evaluatedeviation function
    rs.EnableRedraw(True)
コード例 #17
0
ファイル: Shape Script.py プロジェクト: DougShay/rhinoscripts
def divideCurve(crv):
    aRating = rs.GetInteger("What level of accuracy do you want? (1-10)", 1, 1,
                            10)
    divPoints = aRating / 5 * 200
    divPoints = int(divPoints)
    points = rs.DivideCurve(crv,
                            divPoints,
                            create_points=False,
                            return_points=True)
    return points
コード例 #18
0
def curve_discretisation(curve_guid, discretisation_spacing):
    points = []
    n = int(rs.CurveLength(curve_guid) / discretisation_spacing) + 1
    curve_guids = rs.ExplodeCurves(curve_guid, delete_input=True)

    if len(curve_guids) == 0:
        points += rs.DivideCurve(curve_guid, n)
        if rs.IsCurveClosed(curve_guid):
            points.append(points[0])

    else:
        for guid in curve_guids:
            points += rs.DivideCurve(guid, n)[:-1]
        pts = rs.DivideCurve(curve_guids[-1], n)
        points.append(pts[-1])

    rs.DeleteObjects(curve_guids)

    return rs.AddPolyline(points)
コード例 #19
0
def main():
    surface_id = rs.GetObject("Select a surface to sample", 8, True)
    if not surface_id: return

    curve_id = rs.GetObject("Select a curve to measure", 4, True, True)
    if not curve_id: return

    points = rs.DivideCurve(curve_id, 500)
    rs.EnableRedraw(False)
    for point in points: evaluatedeviation(surface_id, 1.0, point)
    rs.EnableRedraw(True)
コード例 #20
0
	def divide(self, number_of_segments, over_space=False):
		points = []
		rs.EnableRedraw(False)
		if over_space:
			space = self.space(number_of_segments + 1)
			if space:
				points = [list(rs.EvaluateCurve(self.guid, param)) for param in space]
		else:
			points = rs.DivideCurve(self.guid, number_of_segments, create_points=False, return_points=True)
			points[:] = map(list, points)
		rs.EnableRedraw(True)
		return points
コード例 #21
0
def get_boundary_points(crvs_bound,trg_len):
    crvs = rs.ExplodeCurves(crvs_bound,True)
    if not crvs:  crvs = [crvs_bound]
    div_pts = []
    for crv in crvs:
        div = round(rs.CurveLength(crv)/trg_len,0)
        if div < 1: div = 1
        pts = rs.DivideCurve(crv,div)
        div_pts += pts
        
    div_pts = rs.CullDuplicatePoints(div_pts)
    if crvs: rs.DeleteObjects(crvs)
    return div_pts    
コード例 #22
0
def divide_crvs(crvs, div_count):
    points_div = []

    for i in xrange(len(crvs)):
        tmp_pts = rs.DivideCurve(crvs[i], div_count)
        points_div.append(tmp_pts)

    # print points_div
    # print len(points_div)
    # print len(points_div[0])

    ### 2D Array
    return points_div
コード例 #23
0
ファイル: g_instances.py プロジェクト: spkdevelop/SPKCAM
    def OffsetCurve(self, level_cut):

        check_presision = 10
        offset_type = 1
        branched_curves = []
        main_curve = level_cut
        offset_distance = self.general_input["cut_diam"] * self.input_data[
            "xy_dist"]
        curve_1 = rs.OffsetCurve(main_curve,
                                 rs.CurveAreaCentroid(main_curve)[0], -.1,
                                 None, offset_type)
        curve_2 = rs.OffsetCurve(main_curve,
                                 rs.CurveAreaCentroid(main_curve)[0], .1, None,
                                 offset_type)

        if curve_1 and curve_2:
            if len(curve_1) != 1 or len(curve_2) != 1:
                rs.DeleteObjects(curve_1)
                rs.DeleteObjects(curve_2)
                return branched_curves

        mini_test = self.getSmall(curve_1, curve_2)
        do_points = rs.DivideCurve(mini_test, check_presision, False)
        rs.DeleteObjects([curve_1, curve_2])
        do_points.append(rs.CurveAreaCentroid(main_curve)[0])

        for i in range(0, len(do_points)):
            new_offset_curve = rs.OffsetCurve(main_curve, do_points[i],
                                              offset_distance, None,
                                              offset_type)
            try:
                if self.isCurveNew(branched_curves,
                                   new_offset_curve) and rs.IsCurveClosed(
                                       new_offset_curve) and self.isSmall(
                                           new_offset_curve, main_curve):
                    branched_curves.append(new_offset_curve)
                else:
                    rs.DeleteObject(new_offset_curve)
            except:
                if new_offset_curve:
                    rs.DeleteObjects(new_offset_curve)

        for curve in branched_curves:
            rs.ObjectColor(curve, color_palette["cut"])

        if not branched_curves or len(branched_curves) > 1:

            branched_curves.append("sec_plane")

        return branched_curves
コード例 #24
0
def MakeSectionPreview(line, size):
	arrow = []# 目印を格納するリスト
	for i in range(len(line)):
		vec_x = rs.VectorCreate(rs.CurveStartPoint(line[i]), rs.CurveEndPoint(line[i]))
		vec_y = rs.VectorUnitize(rs.VectorCrossProduct(vec_x, [0,0,1]))
		pt3 = rs.DivideCurve(line[i], size)
		seglen = rs.Distance(pt3[0], pt3[1])
		tri_s = [rs.AddPoint(pt3[i]) for i in range(3)]
		tri_e = [rs.AddPoint(pt3[len(pt3) - i]) for i in range(1, 4)]
		rs.MoveObject(tri_s[1], vec_y * (seglen * sqrt(3)))
		rs.MoveObject(tri_e[1], vec_y * (seglen * sqrt(3)))
		arrow.append(rs.AddInterpCurve(rs.coerce3dpointlist(tri_s), 1))
		arrow.append(rs.AddInterpCurve(rs.coerce3dpointlist(tri_e), 1))
	return arrow
コード例 #25
0
def DivideCurveByNumberAndRatio(curve, n, ratio):
    # 根据分段数和比例分段,弧长,含端点
    if ratio == 1:
        return rs.DivideCurve(curve, n)
    n = int(n)
    points = []
    L = rs.CurveLength(curve)
    curveStartPoint = rs.CurveStartPoint(curve)
    curveEndPoint = rs.CurveEndPoint(curve)
    lengths = []
    length0 = L * (1 - ratio) / (1 - ratio**n)
    # print "length0,ratio",length0,ratio
    lengths = list(
        (length0 * (1 - ratio**(i)) / (1 - ratio)) for i in range(n + 1))
    return DivideCurveByLengths(curve, lengths)
コード例 #26
0
    def resample_curve(self, le):
        try:
            # rs_poly = rs.AddPolyline(self.polyline.points)
            crv = rs.AddInterpCurve(self.polyline.points)

            if le <= self.polyline.length:
                a = rs.DivideCurveLength(crv, le, False)
                div = rs.DivideCurveLength(crv, le, False, False)
                new_pts = rs.DivideCurve(crv, len(div), False, True)
                new_par = rs.DivideCurve(crv, len(div), False, False)

            else:
                print('it is a line!')
                new_pts = [rs.CurveStartPoint(crv), rs.CurveEndPoint(crv)]
                new_par = [0.0, rs.CurveLength(crv)]

            out_pts = []
            out_vec = []

            for idx, pt in enumerate(new_pts):

                pt = [pt.X, pt.Y, pt.Z]

                v = rs.CurveTangent(crv, new_par[idx])
                vec = [v.X, v.Y, v.Z]
                # vec = compas.geometry.normalize_vector(vec)

                out_pts.append(pt)
                out_vec.append(vec)
            # print('succesfully resampled')

            return out_pts, out_vec

        except Exception:
            print('Interpolated Curve could not be resampled.')
            return None, None
コード例 #27
0
def extractCrvs(crvs, reso, dir):
    f = open(dir, 'w')
    for i in range(len(crvs)):
        divPts = rs.DivideCurve(crvs[i], reso)
        for j in range(len(divPts)):
            pt = divPts[j]
            f.write(str(pt[0]))
            f.write(',')
            f.write(str(pt[1]))
            f.write(',')
            f.write(str(pt[2]))
            if j < len(divPts) - 1:
                f.write(' ')
        if i < len(crvs) - 1:
            f.write('\n')
    f.close()
コード例 #28
0
 def __init__(self, O):
     self.site = O
     self.add_pts = []
     self.pts = rs.DivideCurve(O, 100)
     b = rs.BoundingBox(self.site)
     poly = rs.AddPolyline([b[0], b[1], b[2], b[3], b[0]])
     div = 10
     u = int((b[1][0] - b[0][0]) / div)
     v = int((b[2][1] - b[1][1]) / div)
     for i in range(int(b[0][0]), int(b[1][0]), u):
         for j in range(int(b[1][1]), int(b[2][1]), v):
             p = [i, j, 0]
             if (rs.PointInPlanarClosedCurve(p, self.site) != 0):
                 #self.add_pts.append(p)
                 self.pts.append(p)
     rs.DeleteObject(poly)
コード例 #29
0
 def getExtendedTP(self, crvList, dist=50, layer_height=2.5):
     result = []
     ptsList = []
     lenList = []
     segmentCount = math.floor(dist / layer_height)
     for crv in crvList:
         tmp = rs.DivideCurve(crv, segmentCount)
         lenList.append(len(tmp))
         ptsList.append(tmp)
     for i in range(min(lenList)):
         tmp = []
         for j in range(len(ptsList)):
             tmp.append(ptsList[j][i])
         tmp.append(ptsList[0][i])
         tmpCrv = rs.AddInterpCurve(tmp, knotstyle=3)
         result.append(tmpCrv)
     result.reverse()
     return result
コード例 #30
0
ファイル: KitsuneVault.py プロジェクト: rsarkozi/Kitsune
        def DivideCurves(curves, NumberOfPoints, treeOut):
            # gorbe felosztasa, pontok listaba es faba rendezese

            pathNum = 0

            for i in range(curves.BranchCount):
                treeBranch = curves.Branch(i)
                treePath = curves.Path(i)

                for j in range(len(treeBranch)):
                    PointsPerCurve = rs.DivideCurve(treeBranch[j],
                                                    NumberOfPoints, True, True)
                    NumOfPtCrv = len(PointsPerCurve)
                    path = ghpath(treePath.AppendElement(j))
                    loopNum = 0

                    while (loopNum < NumOfPtCrv):
                        treeOut.Add(PointsPerCurve[loopNum], path)
                        loopNum = loopNum + 1