コード例 #1
0
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)
コード例 #2
0
def DrawVecSrf(pt1, pt2, pt4):
    strCrvA1 = rs.AddLine(pt1, pt2)
    strCrvA2 = rs.AddLine(pt1, pt4)
    rs.AddEdgeSrf([strCrvA1, strCrvA2])
    strCrvA3 = rs.AddLine(pt2, pt4)

    return
コード例 #3
0
 def left():  #very very computationally heavy. Be patient
     spt = rs.CurveStartPoint(ref)
     r = rs.OffsetCurve(ref, [1, 0, 0], plinth_lst[2])
     r_p = rs.AddEdgeSrf([ref, r])
     guide_curve2 = rs.AddLine(spt, rs.PointAdd(spt, [0, 0, plinth_lst[1]]))
     rs.ExtrudeSurface(r_p, guide_curve2)
     rs.DeleteObjects([guide_curve2, r])
コード例 #4
0
 def right():
     spt = rs.CurveStartPoint(curve)
     l = rs.OffsetCurve(curve, [-1, 0, 0], plinth_lst[2])
     l_p = rs.AddEdgeSrf([curve, l])
     guide_curve1 = rs.AddLine(spt, rs.PointAdd(spt, [0, 0, plinth_lst[1]]))
     rs.ExtrudeSurface(l_p, guide_curve1)
     rs.DeleteObjects([guide_curve1, l])
コード例 #5
0
def surface_from(*curves):
    cs = unvarargs(curves)
    refs = shapes_refs(cs)
    if is_singleton(refs):
        ref = refs[0]
        if isinstance(ref, geo.Point):
            id = ref
        else:
            ids = rh.AddPlanarSrf(refs)
            if ids:
                id = singleton(ids)
            else:
                id = rh.AddPatch(refs, 3, 3)
    elif len(refs) < 0:  #Temporary fix for Funda's problem# 5:
        id = rh.AddEdgeSrf(refs)
    else:
        id = rh.AddPlanarSrf(refs)
    delete_shapes(cs)
    return id
コード例 #6
0
def spiral_stairs(curve, center, start_pt, end_pt, stair_width, steps,
                  plinth_lst, bannister_lst):
    height = end_pt[2] - start_pt[2]
    cen = rs.AddLine(center, rs.PointAdd(center, [0, 0, height]))
    cen_e = rs.CurveEndPoint(cen)
    ref_pts = [n * 1 / steps for n in range(steps + 1)]
    outer_pts = [rs.EvaluateCurve(curve, t) for t in ref_pts]
    inner_pts = [[cen_e[0], cen_e[1], cen_e[2] * t] for t in ref_pts]
    print(inner_pts)
    rise = [0, 0, height / steps]

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

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

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

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

    if bannister_lst[0]:
        curvy_bannister(curve, None, stair_width, bannister_lst)
コード例 #7
0
    def setSurfaceForSlicing(self):
        explodedSurfaces = None

        editPoint = []
        explodedSurfaces = rs.ExplodePolysurfaces(self.addtiveObj)
        for i in explodedSurfaces:
            tmp = rs.SurfaceEditPoints(i)
            for j in tmp:
                editPoint.append(j)

        rs.CullDuplicatePoints(editPoint)

        minValue = []
        maxValue = []
        basePointForPlane = None
        basePointForDistance = None

        for i in range(len(editPoint)):
            if i == 0:
                basePointForPlane = editPoint[0]
                basePointForDistance = editPoint[0]

                for j in range(3):
                    minValue.append(editPoint[0][j])
                    maxValue.append(editPoint[0][j])
                continue

            else:
                if basePointForPlane[2] > editPoint[i][2]:
                    basePointForPlane = editPoint[i]
                if basePointForDistance[2] < editPoint[i][2]:
                    basePointForDistance = editPoint[i]

                for j in range(3):
                    if minValue[j] > editPoint[i][j]:
                        minValue[j] = editPoint[i][j]
                    elif maxValue[j] < editPoint[i][j]:
                        maxValue[j] = editPoint[i][j]

        #why?
        self.basePointForPlane = basePointForPlane

        plane = rs.PlaneFromNormal(basePointForPlane, self.normalVec)

        #calculating distance printing
        forDistance = []
        for i in range(len(editPoint)):
            if i == 0:
                forDistance.append(editPoint[0])
                forDistance.append(rs.DistanceToPlane(plane, editPoint[0]))
            else:
                tmpDistance = rs.DistanceToPlane(plane, editPoint[i])
                if tmpDistance > forDistance[1]:
                    forDistance[0] = editPoint[i]
                    forDistance[1] = tmpDistance

        self.distancePrinting = rs.DistanceToPlane(plane, forDistance[0])
        #adapt to Z Axis
        self.distancePrinting *= (1.0 /
                                  math.cos(math.radians(self.angleOfSurface)))

        if self.distancePrinting < 0:
            self.distancePrinting *= -1

        plane = rs.PlaneFromNormal(basePointForPlane, self.normalVec)

        pntForSur = []
        line = (minValue[0], minValue[1],
                minValue[2]), (minValue[0], minValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (minValue[0], maxValue[1],
                minValue[2]), (minValue[0], maxValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (maxValue[0], maxValue[1],
                minValue[2]), (maxValue[0], maxValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))
        line = (maxValue[0], minValue[1],
                minValue[2]), (maxValue[0], minValue[1], maxValue[2])
        pntForSur.append(rs.LinePlaneIntersection(line, plane))

        lineForSur = []

        for i in range(4):
            lineForSur.append(rs.AddLine(pntForSur[i], pntForSur[(i + 1) % 4]))

        self.sliceSurface = rs.AddEdgeSrf(lineForSur)

        #Delete lines used for making sliceSurface
        rs.DeleteObjects(lineForSur)
        rs.DeleteObjects(explodedSurfaces)
コード例 #8
0
def create_bone(point, curve, length, width, radius, extend):

    if not extend: extend = 0.001
    curve_surface = rs.AddPlanarSrf(curve)
    if not curve_surface:
        exp_curves = rs.ExplodeCurves(curve)
        curve_surface = rs.AddEdgeSrf(exp_curves)
        rs.DeleteObjects(exp_curves)
        print("Surface problem")


#         circle = rs.AddCircle(rs.CurveAreaCentroid(curve)[0],10000)
#         planar_surface = rs.AddPlanarSrf(circle)
#         projected_curve = rs.ProjectCurveToSurface(curve,planar_surface,(0,0,-1))
#         if not projected_curve: rs.ProjectCurveToSurface(curve,planar_surface,(0,0,1))
#         if not projected_curve: print "noooooo"
#         curve_surface = rs.AddPlanarSrf(projected_curve)
#         rs.DeleteObjects([circle,planar_surface,curve])
#         curve = rs.JoinCurves(rs.DuplicateEdgeCurves(curve_surface, select=False))
#         if not curve_surface: print "WARNING"

    main_point_param = rs.CurveClosestPoint(curve, point)
    curve_normal = rs.CurveNormal(curve)
    curve_plane = rs.CurvePlane(curve)
    tangent = rs.CurveTangent(curve, main_point_param)
    center_curve = rs.AddLine((0, 0, 0), rs.VectorScale(tangent, length))
    rs.RotateObject(center_curve, (0, 0, 0), 90, curve_normal)
    rs.MoveObject(center_curve, rs.VectorCreate(point, (0, 0, 0)))
    if not rs.IsPointOnSurface(curve_surface, rs.CurveEndPoint(center_curve)):
        rs.RotateObject(center_curve, point, 180, curve_normal)
    normal = rs.VectorScale(tangent, 10000)
    normal_inverted = rs.VectorReverse(normal)
    side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface,
                                         width / 2)
    if not side_curve:
        side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface,
                                             -width / 2)
    side_curves = [
        side_curve,
        rs.RotateObject(
            side_curve, rs.CurveMidPoint(center_curve), 180,
            rs.VectorCreate(rs.CurveStartPoint(center_curve),
                            rs.CurveEndPoint(center_curve)), True)
    ]
    #side_curves = [side_curve,rs.MirrorObject(side_curve,rs.CurveStartPoint(center_curve),rs.CurveEndPoint(center_curve), True)]
    #side_curves = [rs.OffsetCurveOnSurface(center_curve,curve_surface, width/2),rs.OffsetCurveOnSurface(center_curve,curve_surface, -width/2)]
    for side_curve in side_curves:
        rs.ExtendCurveLength(side_curve, 0, 0, 2)
        rs.ObjectColor(side_curve, (255, 0, 0))
    perimeter_curve = rs.AddCurve([
        rs.CurveStartPoint(side_curves[0]),
        rs.CurveEndPoint(side_curves[0]),
        rs.CurveEndPoint(side_curves[1]),
        rs.CurveStartPoint(side_curves[1]),
        rs.CurveStartPoint(side_curves[0])
    ], 1)
    inside_curve = rs.OffsetCurve(perimeter_curve,
                                  rs.CurveAreaCentroid(perimeter_curve)[0],
                                  radius * .7)
    external_curve = rs.OffsetCurve(perimeter_curve,
                                    rs.CurveAreaCentroid(perimeter_curve)[0],
                                    -extend)

    e_points = [
        rs.CurvePoints(external_curve)[0],
        rs.CurvePoints(external_curve)[3]
    ]
    e_perimeter_curve = rs.AddCurve([
        rs.CurveEndPoint(side_curves[1]),
        rs.CurveEndPoint(side_curves[0]), e_points[0], e_points[1],
        rs.CurveEndPoint(side_curves[1])
    ], 1)

    center_plane_a = rs.PlaneFromPoints(
        rs.CurvePoints(inside_curve)[2],
        rs.CurvePoints(inside_curve)[1],
        rs.CurvePoints(inside_curve)[3])
    center_plane_b = rs.PlaneFromPoints(
        rs.CurvePoints(inside_curve)[1],
        rs.CurvePoints(inside_curve)[0],
        rs.CurvePoints(inside_curve)[2])

    circles = [
        rs.AddCircle(center_plane_a, radius + RADIUS_TOLERANCE),
        rs.AddCircle(center_plane_b, radius + RADIUS_TOLERANCE)
    ]

    bone_curve = rs.CurveBooleanUnion(
        [e_perimeter_curve] +
        circles) if extend else rs.CurveBooleanUnion([perimeter_curve] +
                                                     circles)
    rs.DeleteObjects([
        inside_curve, center_curve, perimeter_curve, curve_surface,
        e_perimeter_curve, external_curve
    ] + side_curves + circles)
    return bone_curve
コード例 #9
0
import rhinoscriptsyntax as rs

curves = rs.GetObjects("Select curves", 4)
rs.AddEdgeSrf(curves)