Example #1
0
    def setPts(self):
        #外周点
        pt0 = [0, 0, 0]
        pt1 = [self.l, 0, 0]
        pt1 = rs.VectorRotate(pt1, self.angle / 2.0, [0, 0, 1])
        pt3 = [self.l, 0, 0]
        pt3 = rs.VectorRotate(pt3, -self.angle / 2.0, [0, 0, 1])
        pt2 = rs.VectorAdd(pt1, pt3)
        self.pts.append(pt0)
        self.pts.append(pt1)
        self.pts.append(pt2)
        self.pts.append(pt3)

        #中点
        for i in range(len(self.pts)):
            if (i == len(self.pts) - 1):
                pt = rs.VectorAdd(self.pts[i], self.pts[0])
                pt = rs.VectorDivide(pt, 2)
            else:
                pt = rs.VectorAdd(self.pts[i], self.pts[i + 1])
                pt = rs.VectorDivide(pt, 2)
            self.midPts.append(pt)

        #楕円
        pt0 = rs.VectorDivide(self.pts[2], 2.0)
        l0 = self.l * math.sin(math.radians(90 / 2.0))
        l1 = self.l * math.cos(math.radians(self.angle / 2.0))
        l2 = self.l * math.sin(math.radians(self.angle / 2.0))
        pt1 = rs.VectorScale([self.l / 2.0, 0, 0], l1 / l0)
        pt1 = rs.VectorAdd(pt0, pt1)
        pt2 = rs.VectorScale([0, self.l / 2.0, 0], l2 / l0)
        pt2 = rs.VectorAdd(pt0, pt2)
        self.ellipsePts.append(pt0)
        self.ellipsePts.append(pt1)
        self.ellipsePts.append(pt2)
Example #2
0
def VectorInternalDivision(vector1, vector2, ratio1, ratio2):
    vector1 = rs.coerce3dvector(vector1)
    vector2 = rs.coerce3dvector(vector2)

    return rs.VectorDivide(
        rs.VectorAdd(rs.VectorScale(vector1, ratio2),
                     rs.VectorScale(vector2, ratio1)), ratio1 + ratio2)
Example #3
0
def FitSurface(srf_id, samples):
    ptSurface = rs.SurfacePoints(srf_id)
    grSurface = rs.SurfaceEditPoints(srf_id, True, True)
    nrSurface = GrevilleNormals(srf_id)

    uvSamples = XYZ_To_UVW(srf_id, samples)
    vecForce = [(0, 0, 0) for p in ptSurface]
    vecFactor = [0 for p in ptSurface]

    #Create null vectors for all control-point forces
    for sample in uvSamples:
        for j in range(len(grSurface)):
            local_distance = (sample[0] - grSurface[j][0])**2 + (
                sample[1] - grSurface[j][1])**2
            local_factor = 100 / (local_distance**2)
            local_force = nrSurface[j]
            local_force = rs.VectorScale(local_force, local_factor * sample[2])
            vecForce[j] = rs.VectorAdd(vecForce[j], local_force)
            vecFactor[j] = vecFactor[j] + local_factor

    for i in range(len(ptSurface)):
        ptSurface[i] = rs.PointAdd(ptSurface[i],
                                   rs.VectorDivide(vecForce[i], vecFactor[i]))

    srf_CP_Count = rs.SurfacePointCount(srf_id)
    srf_Knots = rs.SurfaceKnots(srf_id)
    srf_Weights = rs.SurfaceWeights(srf_id)
    srf_Degree = (rs.SurfaceDegree(srf, 0), rs.SurfaceDegree(srf_id, 1))
    return rs.AddNurbsSurface(srf_CP_Count, ptSurface, srf_Knots[0],
                              srf_Knots[1], srf_Degree, srf_Weights)
Example #4
0
def array_between():


    rs.SelectObject(u)
    m=rs.GetObject('select the curve for path')
    amount = rs.GetInteger('How many objects in array')
    if not amount: return
    p=rs.DivideCurveEquidistant(m,amount,True)
    for i in p:
        point1 = i
        for x in p:
            point2 = x
            vector = rs.VectorCreate(point2, point1)
            copyvec = rs.VectorDivide(vector, amount - 1)

    for v in range(1, amount):
        copy = rs.CopyObject(u, copyvec * v)

    rs.UnselectObject(u)
Example #5
0
def rc_collapse_box():

    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep

    default_KeepLayer = sc.sticky["KeepLayer"] if sc.sticky.has_key(
        "KeepLayer") else False
    default_IgnoreOpen = sc.sticky["IgnoreOpen"] if sc.sticky.has_key(
        "IgnoreOpen") else False
    opt_KeepLayer = Rhino.Input.Custom.OptionToggle(default_KeepLayer, "No",
                                                    "Yes")
    opt_IgnoreOpen = Rhino.Input.Custom.OptionToggle(default_IgnoreOpen, "No",
                                                     "Yes")

    go.SetCommandPrompt("Select Breps")
    go.AddOptionToggle("KeepLayer", opt_KeepLayer)
    go.AddOptionToggle("IgnoreOpenBreps", opt_IgnoreOpen)

    go.GroupSelect = True
    go.SubObjectSelect = False
    go.AcceptEnterWhenDone(True)
    go.AcceptNothing(True)
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.GroupSelect = True
    go.SubObjectSelect = False
    go.DeselectAllBeforePostSelect = False

    res = None
    bHavePreselectedObjects = True

    while True:
        res = go.GetMultiple(1, 0)
        if res == Rhino.Input.GetResult.Option:
            go.EnablePreSelect(False, True)
            continue
        #If not correct
        elif res != Rhino.Input.GetResult.Object:
            rs.Redraw()
            print "No breps were selected!"
            return Rhino.Commands.Result.Cancel
        if go.ObjectsWerePreselected:
            rs.Redraw()
            bHavePreselectedObjects = True
            go.EnablePreSelect(False, True)
            continue
        break

    OPT_IGNORE_OPEN = opt_IgnoreOpen.CurrentValue
    OPT_KEEP_LAYER = opt_KeepLayer.CurrentValue
    sticky["IgnoreOpen"] = OPT_IGNORE_OPEN
    sticky["KeepLayer"] = OPT_KEEP_LAYER

    rs.EnableRedraw(False)

    input_breps = []
    for i in xrange(go.ObjectCount):
        b_obj = go.Object(i).Object()
        input_breps.append(b_obj.Id)

    current_cplane = sc.doc.Views.ActiveView.ActiveViewport.GetConstructionPlane(
    )
    temp_cplane = current_cplane.Plane
    current_cplane.Plane = rs.WorldXYPlane()

    solid_brep_count = 0
    for brep in input_breps:

        if not rs.IsObjectSolid(brep):
            solid_brep_count += 1
            if OPT_IGNORE_OPEN: continue

        if OPT_KEEP_LAYER: brep_layer = rs.ObjectLayer(rs.coerceguid(brep))

        exploded = rs.ExplodePolysurfaces(brep, True)
        remaining_srfs = []
        for srf in exploded:
            norm = rs.SurfaceNormal(srf, [0.5, 0.5])
            if 10 > rs.VectorAngle(norm, [0, 0, 1]) or 10 > rs.VectorAngle(
                    norm, [0, 0, -1]):
                rs.DeleteObject(srf)
            else:
                remaining_srfs.append(srf)
        areas = [rs.SurfaceArea(s) for s in remaining_srfs]
        areas = [x[0] for x in areas]
        srfs, areas = zip(
            *sorted(zip(remaining_srfs, areas), key=lambda x: x[1]))
        pt1, _ = rs.SurfaceAreaCentroid(srfs[-1])
        pt2, _ = rs.SurfaceAreaCentroid(srfs[-2])
        vect = rs.VectorCreate(pt2, pt1)
        vect = rs.VectorDivide(vect, 2)
        rs.MoveObject(srfs[-1], vect)

        if OPT_KEEP_LAYER: rs.ObjectLayer(srfs[-1], brep_layer)
        rs.SelectObjects(srfs[-1])
        rs.DeleteObjects(srfs[:-1])

    rs.EnableRedraw(True)
    rs.Redraw()

    current_cplane.Plane = temp_cplane
    if solid_brep_count > 0:
        outcome = " and were not collapsed." if OPT_IGNORE_OPEN else " and may have been flattened incorrectly. Check input geometry."
        report = str(solid_brep_count) + " brep(s) were not closed" + outcome
        print report
Example #6
0
def drawEhombusTilingByRegularOffsetLine(emblem):
    tmpObjs = []

    # self.rhomboids
    for rhomboid in emblem.rhomboids:
        objs = []

        # 中点長方形の対角四角形
        for i in range(len(rhomboid.midPts)):
            p0 = rhomboid.midPts[i]
            if (i == 0):
                nextMidPt = rhomboid.midPts[i + 1]
                prevtMidPt = rhomboid.midPts[len(rhomboid.midPts) - 1]
            elif (i == len(rhomboid.midPts) - 1):
                nextMidPt = rhomboid.midPts[0]
                prevtMidPt = rhomboid.midPts[i - 1]
            else:
                nextMidPt = rhomboid.midPts[i + 1]
                prevtMidPt = rhomboid.midPts[i - 1]
            p1 = rs.VectorAdd(p0, nextMidPt)
            p1 = rs.VectorDivide(p1, 2.0)
            p2 = rhomboid.ellipsePts[0]
            p3 = rs.VectorAdd(p0, prevtMidPt)
            p3 = rs.VectorDivide(p3, 2.0)
            pts = [p0, p1, p2, p3, p0]
            obj = rs.AddPolyline(pts)
            if (i % 2 == 0):
                rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[1].no)
            else:
                rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[0].no)
            objs.append(obj)

        # 外周面
        pts = []
        for pt in rhomboid.pts:
            pts.append(pt)
        pts.append(pts[0])
        obj = rs.AddPolyline(pts)
        rs.ObjectLayer(obj, "srfRhomboid")
        objs.append(obj)

        # 外周線
        for i in range(len(rhomboid.pts)):
            if (i == len(rhomboid.pts) - 1):
                obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[0])
            else:
                obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[i + 1])
            rs.ObjectLayer(obj, "lineBlack")
            objs.append(obj)

        # rotate
        xform = rs.XformRotation2(rhomboid.rotateAng, [0, 0, 1], [0, 0, 0])
        rs.TransformObjects(objs, xform)

        # move
        rs.MoveObjects(objs, rhomboid.movePt)

        # text
        txt = "%s" % (rhomboid.name)
        pt = rhomboid.getAbsolutePt(rhomboid.ellipsePts[0])
        height = 1.2
        pt = [pt[0], pt[1] + height / 2.0, pt[2]]
        obj = rs.AddText(txt,
                         pt,
                         height,
                         font,
                         font_style=0,
                         justification=2 + 65536)
        rs.ObjectLayer(obj, "textRhomboid")
        objs.append(obj)

        # tmpObjs
        for obj in objs:
            tmpObjs.append(obj)

    # move to center
    pts = rs.BoundingBox(tmpObjs)
    center = rs.VectorAdd(pts[0], pts[2])
    center = rs.VectorScale(center, 0.5)
    center = rs.VectorSubtract([0, 0, 0], center)
    rs.MoveObjects(tmpObjs, center)

    return tmpObjs
Example #7
0
def drawRhombusOnRegularOffsetLine(emblem):
    tmpObjs = []
    for rhomboid in emblem.rhomboids:
        objs = []

        # 中点長方形の対角四角形
        for i in range(len(rhomboid.midPts)):
            p0 = rhomboid.midPts[i]
            if (i == 0):
                nextMidPt = rhomboid.midPts[i + 1]
                prevtMidPt = rhomboid.midPts[len(rhomboid.midPts) - 1]
            elif (i == len(rhomboid.midPts) - 1):
                nextMidPt = rhomboid.midPts[0]
                prevtMidPt = rhomboid.midPts[i - 1]
            else:
                nextMidPt = rhomboid.midPts[i + 1]
                prevtMidPt = rhomboid.midPts[i - 1]
            p1 = rs.VectorAdd(p0, nextMidPt)
            p1 = rs.VectorDivide(p1, 2.0)
            p2 = rhomboid.ellipsePts[0]
            p3 = rs.VectorAdd(p0, prevtMidPt)
            p3 = rs.VectorDivide(p3, 2.0)
            pts = [p0, p1, p2, p3, p0]
            obj = rs.AddPolyline(pts)
            if (i % 2 == 0):
                rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[1].no)
            else:
                rs.ObjectLayer(obj, "srf%s" % rhomboid.lines[0].no)
            objs.append(obj)

        # 外周面
        pts = []
        for pt in rhomboid.pts:
            pts.append(pt)
        pts.append(pts[0])
        obj = rs.AddPolyline(pts)
        rs.ObjectLayer(obj, "srfRhomboid")
        objs.append(obj)

        # 外周線
        for i in range(len(rhomboid.pts)):
            if (i == len(rhomboid.pts) - 1):
                obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[0])
            else:
                obj = rs.AddLine(rhomboid.pts[i], rhomboid.pts[i + 1])
            rs.ObjectLayer(obj, "lineBlack")
            objs.append(obj)

        # move to center
        objs = rs.MoveObjects(objs, [
            -rhomboid.ellipsePts[0][0], -rhomboid.ellipsePts[0][1],
            -rhomboid.ellipsePts[0][2]
        ])

        # rotate
        xform = rs.XformRotation2(rhomboid.rotateAng, [0, 0, 1], [0, 0, 0])
        rs.TransformObjects(objs, xform)

        # move
        pts = rs.LineLineIntersection(
            [rhomboid.lines[0].sPt, rhomboid.lines[0].ePt],
            [rhomboid.lines[1].sPt, rhomboid.lines[1].ePt])
        rs.MoveObjects(objs, pts[0])

        # tmpObjs
        for obj in objs:
            tmpObjs.append(obj)

    return tmpObjs
Example #8
0
def DivideVectorArray(Vectors, Factors):
    rc = [rs.VectorDivide(Vectors[i], Factors[i]) for i in range(len(Vectors))]
    return rc