Exemple #1
0
 def create_jig(self, list):
     jigs = []
     for i in range(0, len(list), 2):
         domain = rs.CurveDomain(list[i])
         start_point = rs.EvaluateCurve(list[i], domain[0])
         end_point = rs.EvaluateCurve(list[i], domain[1])
         start_plane = rs.PlaneFromNormal(
             start_point, rs.VectorUnitize(end_point - start_point))
         end_plane = rs.PlaneFromNormal(
             end_point, rs.VectorUnitize(start_point - end_point))
         start_curve_point = self.closest_intersection(
             rs.PlaneCurveIntersection(start_plane, self.curve_object),
             start_point)
         end_curve_point = self.closest_intersection(
             rs.PlaneCurveIntersection(end_plane, self.curve_object),
             end_point)
         start_vector = rs.VectorUnitize(
             rs.VectorCreate(start_point, start_curve_point))
         end_vector = rs.VectorUnitize(
             rs.VectorCreate(end_point, end_curve_point))
         start_vector_scale = rs.VectorScale(start_vector, -5)
         end_vector_scale = rs.VectorScale(end_vector, -5)
         start_square = self.create_square(
             rs.PointAdd(start_point, start_vector_scale),
             rs.PointAdd(end_point, end_vector_scale), start_vector)
         end_square = self.create_square(
             rs.PointAdd(end_point, end_vector_scale),
             rs.PointAdd(start_point, start_vector_scale), end_vector)
         jigs.append(self.create_jig_section(start_square, end_square))
     return jigs
 def grow(self, side):
     newBranches = []
     if len(self.branches) == 0:
         self.startBranch()
     for i in range(len(self.branches)):
         self.pullBranch(self.branches[i])
         axis01 = self.findAxis(self.branches[i].end01)
         axis02 = self.findAxis(self.branches[i].end02)
         if rs.VectorAngle(self.branches[i].axis,
                           axis01) < 60 and side == 1:
             param = rs.CurveClosestPoint(self.path, self.branches[i].end01)
             dist = rs.Distance(self.branches[i].end01,
                                rs.EvaluateCurve(self.path, param))
             tan = rs.CurveTangent(self.path, param)
             newBranches.append(
                 branch(self.branches[i].end01, self.branches[i].vec01,
                        self.ang, axis01))
         if rs.VectorAngle(self.branches[i].axis,
                           axis02) < 60 and side == 2:
             param = rs.CurveClosestPoint(self.path, self.branches[i].end02)
             dist = rs.Distance(self.branches[i].end02,
                                rs.EvaluateCurve(self.path, param))
             tan = rs.CurveTangent(self.path, param)
             vecAng = rs.VectorAngle(self.branches[i].vec02, tan)
             vec = rs.VectorRotate(self.branches[i].vec02, -vecAng / 5,
                                   axis02)
             newBranches.append(
                 branch(self.branches[i].end02, self.branches[i].vec02,
                        self.ang, axis02))
     self.branches = []
     self.branches.extend(newBranches)
     return self.branches
Exemple #3
0
def double_pitch(m, n, o, p, diffY, diffZ):
    """generates a double pitch roof"""
    # cullis
    cullisN = rs.AddLine(m, n)
    cullisP = rs.AddLine(p, o)

    # ridge
    cullisO = rs.AddLine(n, o)
    domainO = rs.CurveDomain(cullisO)

    cullisM = rs.AddLine(p, m)
    domainM = rs.CurveDomain(cullisM)

    midCullisO = rs.EvaluateCurve(cullisO, (domainO[1] / 2.0))
    midCullisM = rs.EvaluateCurve(cullisM, (domainM[1] / 2.0))

    ridgeM = rs.PointAdd(rs.PointAdd(midCullisM, [0, 0, diffZ]), [0, diffY, 0])
    ridgeO = rs.PointAdd(rs.PointAdd(midCullisO, [0, 0, diffZ]),
                         [0, -diffY, 0])
    ridge = rs.AddLine(ridgeM, ridgeO)

    allGeometry.append(rs.AddLoftSrf([cullisN, ridge]))
    allGeometry.append(rs.AddLoftSrf([cullisP, ridge]))

    # gable
    ridgeOPt = ridgeO
    ridgeMPt = ridgeM
    #    print(m)
    #    print(ridgeMPt)
    #    print(p)
    allGeometry.append(rs.AddSrfPt([m, ridgeMPt, p]))
    allGeometry.append(rs.AddSrfPt([n, ridgeOPt, o]))
Exemple #4
0
	def renderSubTree(self, startRadius, growthFactor, curveDegree):
		#start radius is the radius at the tip of the smallest branches
		#growth Factor is the factor by which the start radius grows
		#as it moves towards the root, node by node
		#curveDegree is the degree of the curves of the tree
		
		treeID = rs.AddGroup()
		while True:
			deepCh = self.deepestChild()
			startNode = deepCh[0]
			if startNode == None:
				#this is the case where the whole tree is rendered
				#later return the group id of the group
				#that contains the whole tree from here
				return treeID
			
			curNode = startNode
			nodeList = [startNode]
			while (not curNode.parent is None) and (not curNode.isDone):
				nodeList.append(curNode.parent)
				curNode = curNode.parent
			
			posList = []
			i = 0
			while i < len(nodeList):
				posList.append(nodeList[i].pos)
				i += 1
			
			curveID = rs.AddCurve(posList,curveDegree)
			curDom = rs.CurveDomain(curveID)
			node1 = rs.EvaluateCurve(curveID, curDom[0])
			node2 = rs.EvaluateCurve(curveID, curDom[1])
			tan1 = rs.CurveTangent(curveID, curDom[0])
			tan2 = rs.CurveTangent(curveID, curDom[1])
			
			plane1 = rs.PlaneFromNormal(node1, tan1)
			plane2 = rs.PlaneFromNormal(node2, tan2)
			radius1 = startRadius
			radius2 = (growthFactor**len(nodeList))*startRadius
			
			circles = []
			circles.append(rs.AddCircle(plane1, radius1))
			circles.append(rs.AddCircle(plane2, radius2))
			
			branch = rs.AddSweep1(curveID, circles, True)
			
			rs.AddObjectToGroup(branch, treeID)
			
			rs.DeleteObjects(circles)
			rs.DeleteObject(curveID)
			
			
			
			for nd in nodeList:
				nd.isDone = True
def periods_ofcurve(curve, n):
    domain = rs.CurveDomain(curve)
    cpoint_list = []
    point0 = rs.EvaluateCurve(curve, domain[0])
    point1 = rs.EvaluateCurve(curve, domain[1])
    #rs.AddPoints( [ point0, point1 ] )
    for i in range(n + 1):
        d = domain[1] * (i) / n
        point_lower = rs.EvaluateCurve(curve, d - a)
        point_upper = rs.EvaluateCurve(curve, d + a)
        cpoint_list.append(point_lower)
        cpoint_list.append(point_upper)
    return cpoint_list
def curvy_stairs(curve, start_pt, end_pt, stair_width, steps, plinth_lst,
                 bannister_lst):
    ref = rs.OffsetCurve(
        curve, [1, 0, 0],
        stair_width)  # create the second curve to guide the stair
    ref_pts = [n * 1 / steps for n in range(steps + 1)
               ]  # guide points to divide up the curve
    left_pts = [rs.EvaluateCurve(curve, t)
                for t in ref_pts]  # guide points on input curve
    right_pts = [rs.EvaluateCurve(ref, t)
                 for t in ref_pts]  #guide points on the offset curve
    height = end_pt[2] - start_pt[2]  #stair height
    rise = [0, 0, height / steps]  # a vector

    for i in range(steps):
        #draw rise
        v_ver = [
            left_pts[i], right_pts[i],
            rs.PointAdd(right_pts[i], rise),
            rs.PointAdd(left_pts[i], rise)
        ]
        rs.AddSrfPt(v_ver)

        #draw run
        v_hori = [v_ver[3], v_ver[2], right_pts[i + 1], left_pts[i + 1]]
        rs.AddSrfPt(v_hori)

        #draw sides
        s1 = rs.AddLine(left_pts[i], rs.PointAdd(left_pts[i], rise))
        s2 = rs.AddLine(rs.PointAdd(left_pts[i], rise), left_pts[i + 1])
        s3 = rs.AddSubCrv(curve, rs.CurveClosestPoint(curve, left_pts[i]),
                          rs.CurveClosestPoint(curve, left_pts[i + 1]))
        rs.AddEdgeSrf([s1, s2, s3])
        rs.DeleteObjects([s1, s2, s3])
        s1 = rs.AddLine(right_pts[i], rs.PointAdd(right_pts[i], rise))
        s2 = rs.AddLine(rs.PointAdd(right_pts[i], rise), right_pts[i + 1])
        s3 = rs.AddSubCrv(ref, rs.CurveClosestPoint(ref, right_pts[i]),
                          rs.CurveClosestPoint(ref, right_pts[i + 1]))
        rs.AddEdgeSrf([s1, s2, s3])
        rs.DeleteObjects([s1, s2, s3])

    s1 = rs.AddLine(left_pts[0], right_pts[0])
    s2 = rs.AddLine(left_pts[-1], right_pts[-1])
    rs.AddEdgeSrf([s1, curve, s2, ref])
    rs.DeleteObjects([s1, s2])

    if plinth_lst[0]:
        curvy_plinth(curve, ref, stair_width, plinth_lst)

    if bannister_lst[0]:
        curvy_bannister(curve, ref, stair_width, bannister_lst)
def get_inscribed_radius(curve, origin=(0,0,0)):

    # find out how many segments in this curve
    nsegs = rs.PolyCurveCount(curve)

    # record closest distance & point
    best_r = None
    best_point = None

    # for each curve segment
    for seg in range(nsegs):
        # get the curve parameter (i.e. input to spline function) that
        # approaches the origin most closely for this segment.
        param = rs.CurveClosestPoint(curve, origin, seg)

        # evaluate the curve at that parameter to get 3D point location
        point = rs.EvaluateCurve(curve, param)

        # get the displacement from the origin
        point = mz.vec_sub(list(point), origin)

        # get length
        r = mz.vec_length(point)

        # update best 
        if best_r is None or r < best_r:
            best_r = r
            best_point = point

    # return distance & point
    return best_r, best_point
def get_dist(pt,poly):
    # find closest point on axis curve
    param = rs.CurveClosestPoint(axis, pt)
    # get plane perpendicular to curve
    ck,pl = axis.PerpendicularFrameAt(param)
    # part responsible for flat end caps
    # if distance from point to plane is bigger than 0,
    # return that distance
    pp = rs.PlaneClosestPoint(pl,pt)
    d2 = rs.Distance(pt,pp)
    if d2>0.01:
        return d2

    # else change the basis of the polygon from world xy
    # to that plane to check for distance and inside/outside
    pm = (param-axis.Domain[0])/(axis.Domain[1]-axis.Domain[0])

    wxy = rs.WorldXYPlane()
    tf = rg.Transform.PlaneToPlane(wxy,pl)
    ang = sa + pm*(ea-sa)
    tr = rg.Transform.Rotation(ang, pl.Normal, pl.Origin)
    tpts = rs.CurvePoints(poly)
    for p in tpts:
        p.Transform(tf)
        p.Transform(tr)
    ply = rs.AddPolyline(tpts)
    prm = rs.CurveClosestPoint(ply,pt)
    cp = rs.EvaluateCurve(ply,prm)
    d = rs.Distance(pt,cp)
    # if the point is inside the curve, reverse the distance
    bln = rs.PointInPlanarClosedCurve(pt,ply,pl)
    if bln:
        d *= -1
    return d
Exemple #9
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
def get_dist(p, j):
    param = rs.CurveClosestPoint(axis[j], p)
    cp = rs.EvaluateCurve(axis[j], param)
    dv = map_values(param, axis[j].Domain[0], axis[j].Domain[1], 0, 1)
    r = (1 - dv) * start_radius[j] + dv * end_radius[j]
    d = rs.Distance(p, cp) - r
    return d
Exemple #11
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
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
Exemple #13
0
 def heightfield(self, density):
     heightfield = []
     space = self.space(density)
     if space:
         xyz = [rs.EvaluateCurve(self.guid, param) for param in space]
         heightfield = map(list, xyz)
     return heightfield
    def distance(self):

        Udomain = rs.SurfaceDomain(self.strsrf, 0)
        Vdomain = rs.SurfaceDomain(self.strsrf, 1)

        stepU = (Udomain[1] - Udomain[0]) / self.intu
        stepV = (Vdomain[1] - Vdomain[0]) / self.intv

        #PLOT POINTS ON SURFACE)
        for i in range(self.intu + 1):
            for j in range(self.intv + 1):

                #define u and v in terms of step values and i and j
                u = Udomain[0] + stepU * i
                v = Vdomain[0] + stepV * j

                point = rs.EvaluateSurface(self.strsrf, u, v)

                crvParam = rs.CurveClosestPoint(self.Crv, point)
                crvPoints = rs.EvaluateCurve(self.Crv, crvParam)

                if rs.Distance(point, crvPoints) < 400:
                    self.dis[(i, j)] = rs.Distance(point, crvPoints)
                else:
                    self.dis[(i, j)] = 1300

        return self.dis
Exemple #15
0
def RunCommand(is_interactive):
    if "FOFIN" not in sc.sticky:
        print("Initialise the plugin first!")
        return

    FOFIN = sc.sticky["FOFIN"]
    if not FOFIN["cablenet"]:
        return

    for key, attr in FOFIN["cablenet"].vertices(True):
        rail = find_constraint(attr["constraint"])
        if rail:
            if attr["param"] is None:
                _, t = rail.Geometry.ClosestPoint(
                    Point3d(attr["x"], attr["y"], attr["z"]), 0.0)
                attr["param"] = t
            else:
                t = attr["param"]
            point = rs.EvaluateCurve(rail, t)
            x, y, z = list(point)
            attr["x"] = x
            attr["y"] = y
            attr["z"] = z

    FOFIN["cablenet"].draw(layer=FOFIN["settings"]["layer"],
                           clear_layer=True,
                           settings=FOFIN["settings"])
Exemple #16
0
    def kinks(self, threshold=1e-3):
        """Return the XYZ coordinates of kinks, i.e. tangency discontinuities, along the surface's boundaries.

        Returns
        -------
        list
            The list of XYZ coordinates of surface boundary kinks.

        """
        kinks = []
        borders = self.borders(type=0)

        for border in borders:
            border = RhinoCurve(border)
            extremities = map(
                lambda x: rs.EvaluateCurve(border.guid,
                                           rs.CurveParameter(border.guid, x)),
                [0., 1.])

            if border.is_closed():
                start_tgt, end_tgt = border.tangents(extremities)
                if angle_vectors(start_tgt, end_tgt) > threshold:
                    kinks += extremities

            else:
                kinks += extremities

        return list(set(kinks))
def splitlines(lines, count):
    #temp list and clear input list
    templines = lines
    lines = []
    pts = []
    #make sure we have a way to break the recursion
    if count == 0:
        return 1
    else:
        for line in templines:
            #get properties of the line (endpts, length, direction, domain)
            stpt = rs.CurveStartPoint(line)
            endpt = rs.CurveEndPoint(line)
            length = rs.Distance(stpt, endpt)
            dir1 = rs.VectorCreate(endpt, stpt)
            crvdomain = rs.CurveDomain(line)
            #parameters for midpt and pts 1/3 and 2/3 along the line
            t0 = crvdomain[1] / 2.0
            t1 = crvdomain[1] / 3.0
            t2 = t1 * 2
            midpt = rs.EvaluateCurve(line, t0)
            ptatonethird = rs.EvaluateCurve(line, t1)
            ptattwothird = rs.EvaluateCurve(line, t2)

            midpt = rs.AddPoint(midpt)
            #call get normal function
            normal = getnormal(stpt, endpt)
            #move midpt perpendicular to line at 1/3 the length of the line
            scaled = rs.VectorScale(normal, 0.3333)
            rs.MoveObject(midpt, scaled)
            #create the 4 newlines and add them to the list
            newline1 = rs.AddLine(stpt, ptatonethird)
            newline2 = rs.AddLine(ptatonethird, midpt)
            newline3 = rs.AddLine(midpt, ptattwothird)
            newline4 = rs.AddLine(ptattwothird, endpt)
            lines.append(newline1)
            lines.append(newline2)
            lines.append(newline3)
            lines.append(newline4)
            #create a list of objects to delete
            cleanup = []
            cleanup.append(line)
            cleanup.append(midpt)
            rs.DeleteObjects(cleanup)
        #don't forget to decrement the count otherwise infinite loop
        count = count - 1
        return splitlines(lines, count)
Exemple #18
0
 def get_distance(self,x,y,z):
     p = rs.CreatePoint(x,y,z)
     param=rs.CurveClosestPoint(self.c, p)
     cp=rs.EvaluateCurve(self.c,param)
     dv = map_values(param,self.c.Domain[0],self.c.Domain[1],0,1)
     r = (1-dv)*self.r1 + dv*self.r2
     d = rs.Distance(p,cp) - r
     return d
Exemple #19
0
def EdgeVectors(srf, pts):
    crvs = rs.DuplicateEdgeCurves(srf)
    edgeVectors = []
    for pt in pts:
        closestIndex = 0
        closestDist = 99999
        for i, crv in enumerate(crvs):
            tempPt = rs.EvaluateCurve(crv, rs.CurveClosestPoint(crv, pt))
            dist = rs.Distance(pt, tempPt)
            if dist < closestDist:
                closestDist = dist
                closestIndex = i
        
        tempPt = rs.EvaluateCurve(crvs[closestIndex], rs.CurveClosestPoint(crvs[closestIndex], pt))
        rs.AddLine(tempPt, pt)
        edgeVectors.append(rs.VectorCreate(tempPt, pt))
    return edgeVectors
 def right():
     r_curve = rs.CopyObject(curve, [0, 0, b_lst[1]])
     rs.AddPipe(r_curve, 0, b_lst[2], cap=1)
     rs.DeleteObjects(r_curve)
     pts = [rs.EvaluateCurve(curve, t) for t in ref_pts]
     for i in range(b_lst[3]):
         base = rs.PointAdd(pts[i], [0, 0, b_lst[1]])
         rs.AddCylinder(pts[i], base, b_lst[4])
def addpointat_r1_parameter(curve_id, parameter):
    domain = rs.CurveDomain(curve_id)
    if not domain: return

    r1_param = domain[0] + parameter * (domain[1] - domain[0])
    r3point = rs.EvaluateCurve(curve_id, r1_param)
    if r3point:
        point_id = rs.AddPoint(r3point)
        rs.ObjectColor(point_id, parametercolor(parameter))
Exemple #22
0
def chain(ch, lh, i):
    while i > 0:
        temp1 = rs.AddLine(ch[i], ch[i-1])
    if lh[i-1] > 0: temp2 = rs.EvaluateCurve(temp1, lh[i-1])
    if lh[i-1] == 0: temp2 = ch[i]
    ch[i-1] = temp2
    #rs.DeleteObject(temp1)
    i = i - 1
    return ch
def is_point_on_curve(curve_guid, point_xyz):
    geom_key = geometric_key(point_xyz)
    t = rs.CurveClosestPoint(curve_guid, point_xyz)
    pt_on_crv = rs.EvaluateCurve(curve_guid, t)
    geom_key_pt_on_crv = geometric_key(pt_on_crv)
    if geom_key == geom_key_pt_on_crv:
        return True
    else:
        return False
def automated_smoothing_constraints(mesh, points = None, curves = None, surface = None, mesh2 = None):
	"""Apply automatically point, curve and surface constraints to the vertices of a mesh to smooth.

	Parameters
	----------
	mesh : Mesh
		The mesh to apply the constraints to for smoothing.
	points : list
		List of XYZ coordinates on which to constrain mesh vertices. Default is None.
	curves : list
		List of Rhino curve guids on which to constrain mesh vertices. Default is None.
	surface : Rhino surface guid
		A Rhino surface guid on which to constrain mesh vertices. Default is None.
	mesh2 : Rhino mesh guid
		A Rhino mesh guid on which to constrain mesh vertices. Default is None.

	Returns
	-------
	constraints : dict
		A dictionary of mesh constraints for smoothing as vertex keys pointing to point, curve or surface objects.

	"""

	if surface:
		surface = RhinoSurface.from_guid(surface)
	if curves:
		curves = [RhinoCurve.from_guid(curve) for curve in curves]
	if mesh2:
		mesh2 = RhinoMesh.from_guid(mesh2)

	constraints = {}
	constrained_vertices = {}

	vertices = list(mesh.vertices())
	vertex_coordinates = [mesh.vertex_coordinates(vkey) for vkey in mesh.vertices()]
	
	if points is not None and len(points) != 0:
		constrained_vertices.update({vertices[closest_point_in_cloud(rs.PointCoordinates(point), vertex_coordinates)[2]]: point for point in points})

	if mesh2 is not None:
		constraints.update({vkey: mesh2.guid for vkey in mesh.vertices()})

	if surface is not None:
		constraints.update({vkey: surface.guid for vkey in mesh.vertices()})
	
	if curves is not None and len(curves) != 0:
		boundaries = [split_boundary for boundary in mesh.boundaries() for split_boundary in list_split(boundary, [boundary.index(vkey) for vkey in constrained_vertices.keys() if vkey in boundary])]
		boundary_midpoints = [Polyline([mesh.vertex_coordinates(vkey) for vkey in boundary]).point(t = .5) for boundary in boundaries]
		curve_midpoints = [rs.EvaluateCurve(curve, rs.CurveParameter(curve, .5)) for curve in curves]
		midpoint_map = {i: closest_point_in_cloud(boundary_midpoint, curve_midpoints)[2] for i, boundary_midpoint in enumerate(boundary_midpoints)}
		constraints.update({vkey: curves[midpoint_map[i]].guid for i, boundary in enumerate(boundaries) for vkey in boundary})
	
	if points is not None:
		constraints.update(constrained_vertices)

	return constraints
Exemple #25
0
def ColorBySize():
    try:
        objs = rs.GetObjects("Select objects to color",
                             1073815613,
                             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)

        areas = []
        for obj in objs:
            if rs.IsCurve(obj):
                if rs.IsCurveClosed(obj):
                    areas.append(rs.CurveArea(obj)[0])
                else:
                    areas.append(rs.CurveLength(obj))
            elif rs.IsSurface(obj):
                areas.append(rs.SurfaceArea(obj)[0])
            elif rs.IsPolysurface(obj):
                if rs.IsPolysurfaceClosed(obj):
                    areas.append(rs.SurfaceVolume(obj)[0])
            elif rs.IsHatch(obj):
                areas.append(rs.Area(obj))
            else:
                print "Only curves, hatches, and surfaces supported"
                return

        newAreas = list(areas)
        objAreas = zip(newAreas, objs)
        objAreas.sort()
        objSorted = [objs for newAreas, objs in objAreas]

        areas.sort()
        normalParams = utils.RemapList(areas, 0, 1)

        colors = []
        for t in normalParams:
            param = rs.CurveParameter(colorLine, t)
            colors.append(rs.EvaluateCurve(colorLine, param))

        for i, obj in enumerate(objSorted):
            rs.ObjectColor(obj, (colors[i].X, colors[i].Y, colors[i].Z))

        rs.DeleteObject(colorLine)
        rs.EnableRedraw(True)
        return True
    except:
        return False
Exemple #26
0
def extframe(srf):
    crv = rs.DuplicateSurfaceBorder(srf, type=1)
    point = rs.EvaluateCurve(crv, 0)
    parameter = rs.SurfaceClosestPoint(srf, point)
    plane = rs.SurfaceFrame(srf, parameter)
    direction = rs.CurveTangent(crv, 0)
    newplane = rs.PlaneFromNormal(point, direction, plane.ZAxis)
    frame = sweepSec(crv, newplane, vec1)
    if crv: rs.DeleteObjects(crv)
    return frame
Exemple #27
0
def rampIntersection(route1, route2, width):
    edges = []
    offSeg1 = offsetLine(route1, width / 2)
    offSeg2 = offsetLine(route2, width / 2)
    test1 = rs.CurveCurveIntersection(offSeg1, offSeg2)
    if (test1 == None):
        side1 = False
    else:
        side1 = True
    offSeg3 = offsetLine(route1, -width / 2)
    offSeg4 = offsetLine(route2, -width / 2)
    rs.ObjectColor(offSeg3, [255, 0, 0])
    rs.ObjectColor(offSeg4, [255, 0, 0])
    test2 = rs.CurveCurveIntersection(offSeg3, offSeg4)
    if (test2 == None):
        side2 = False
    else:
        side2 = True
    if (side1):
        pivotPt = rs.LineLineIntersection(offSeg1, offSeg2)[0]
        perpPt1 = rs.EvaluateCurve(offSeg3,
                                   rs.CurveClosestPoint(offSeg3, pivotPt))
        perpPt2 = rs.EvaluateCurve(offSeg4,
                                   rs.CurveClosestPoint(offSeg4, pivotPt))
        edges.append(rs.AddLine(pivotPt, perpPt1))
        edges.append(rs.AddLine(pivotPt, perpPt2))
        elbowPt = rs.LineLineIntersection(offSeg3, offSeg4)[0]
    else:
        pivotPt = rs.LineLineIntersection(offSeg3, offSeg4)[0]
        perpPt1 = rs.EvaluateCurve(offSeg1,
                                   rs.CurveClosestPoint(offSeg1, pivotPt))
        perpPt2 = rs.EvaluateCurve(offSeg2,
                                   rs.CurveClosestPoint(offSeg2, pivotPt))
        edges.append(rs.AddLine(pivotPt, perpPt1))
        edges.append(rs.AddLine(pivotPt, perpPt2))
        elbowPt = rs.LineLineIntersection(offSeg1, offSeg2)[0]
    rs.DeleteObject(offSeg1)
    rs.DeleteObject(offSeg2)
    rs.DeleteObject(offSeg3)
    rs.DeleteObject(offSeg4)
    landing = rs.AddPolyline([pivotPt, perpPt1, elbowPt, perpPt2, pivotPt])
    return edges, landing
Exemple #28
0
def draw_warp():
    n = 360
    warp = []
    for i in rs.frange(0, n, d):
        point = []
        for z in rs.frange(1, 120, 5):
            si = draw_sikaku(i)
            do = draw_outline(z)
            p = rs.CurveSurfaceIntersection(do, si)
            rs.DeleteObject(si)
            rs.DeleteObject(do)
            point.append(p[0][1])

        curve_1 = rs.AddCurve(point)
        curve_2 = rs.CopyObject(curve_1, polar(t, i, 0))

        domain = rs.CurveDomain(curve_1)
        increment = (domain[1] - domain[0])

        point_1 = rs.EvaluateCurve(curve_1, domain[0])
        point_2 = rs.EvaluateCurve(curve_1, domain[1])

        arc_1 = draw_arc(point_1, i, -1)
        arc_2 = draw_arc(point_2, i, 1)

        wakame = [curve_1, curve_2, arc_1, arc_2]

        #konobubunnde_ugokasiteru
        #        rs.RotateObjects(wakame,(0,0,0),90,polar(10,i,0),False)
        #        rs.MoveObjects  (wakame, polar(0, i ,0))
        #        rs.RotateObjects(wakame,(0,0,0),-i,None,False)
        #        rs.MoveObjects  (wakame, (i*t/5,10,5))
        #konobubunnde_ugokasiteru

        point_3 = rs.EvaluateCurve(curve_1, increment * 28 / 29)
        rec_1 = draw_rectangle_2(point_3, 0)
        point_4 = rs.EvaluateCurve(curve_1, increment * 1 / 14)
        rec_2 = draw_rectangle_2(point_4, 0)

        warp.append(curve_1)

    return warp
Exemple #29
0
    def points_from_ellipse(self, index):
        ellipse = self.cross_sections[index]
        even = index % 2 == 0

        ellipse_domain = rs.CurveDomain(ellipse)
        ellipse_step = (ellipse_domain[1] -
                        ellipse_domain[0]) / self.POINTS_ON_CROSS_SECTION
        points = []

        j = 0
        for i in rs.frange(ellipse_domain[0], ellipse_domain[1] - ellipse_step,
                           ellipse_step):
            if even:
                if j % 2 == 0:
                    points.append(rs.EvaluateCurve(ellipse, i))
            else:
                if (j + 1) % 2 == 0:
                    points.append(rs.EvaluateCurve(ellipse, i))
            j += 1
        return points
def draw_hole(grid00, grid01):
    grids = [grid00, grid01]
    points = []
    lists = []
    for i in grids:
        domain = rs.CurveDomain(i)
        domains = [domain[0] + b, domain[1] - b0 * b, domain[1] - b]
        lists.append(domains)
        for ii in domains:
            point = rs.EvaluateCurve(i, ii)
            points.append(point)
    for i in range(2):
        grid = rs.AddCurve([points[i * 3], points[5 - i * 3]])
        domain0 = rs.CurveDomain(grid)
        domain1 = domain0[1] - c
        point = rs.EvaluateCurve(grid, domain1)
        #rs.AddPoint(point)
        rs.AddCurve([point, points[i * 3 + 1]])
        rs.TrimCurve(grids[i], (lists[i][0], lists[i][1]))
        rs.TrimCurve(grid, (domain0[0], domain1))