Example #1
0
def Elt(refpt,dir,data):
    
    
    xform = Transform(dir,rs.VectorRotate(dir,90,[0,0,1]),refpt)
    
    L = []
    R = []
    
    
    for point in data[2]:
        
        trans = rs.VectorTransform(point,xform)
        trans = rs.VectorAdd(trans,refpt)
        L.append(trans)
        
    
    for point in data[3]:
        
        trans = rs.VectorTransform(point,xform)
        trans = rs.VectorAdd(trans,refpt)
        R.append(trans)
        
    
    trans = rs.VectorTransform(data[4],xform)
    
    return [trans,L,R]
    def update(self):
        self.posP = self.pos
        # call the behaviors
        velboids1 = self.AlignmentVector()
        velboids2 = self.SeparationVector()
        velboids3 = self.CohesionVector()
        velav = self.avoid()
        veltrail = self.trail(4)

        # scale the behaviors
        velboids1 = rs.VectorScale(velboids1, 0.1)
        velboids2 = rs.VectorScale(velboids2, 0.1)
        velboids3 = rs.VectorScale(velboids3, 0.2)
        velav = rs.VectorScale(velav, 0.8)
        veltrail = rs.VectorScale(veltrail, 20)

        # add the behaviors to the vel
        #self.vel = rs.VectorAdd (self.vel, velboids1)
        self.vel = rs.VectorAdd(self.vel, velboids2)
        self.vel = rs.VectorAdd(self.vel, velboids3)
        self.vel = rs.VectorAdd(self.vel, velav)
        self.vel = rs.VectorAdd(self.vel, veltrail)

        # update pos

        self.vel = vectorlimit(self.vel, self.mv)

        self.pos = rs.VectorAdd(self.pos, self.vel)
Example #3
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 #4
0
def offsetLine(line, dist):
    norm = rs.VectorRotate(rs.CurveTangent(line, rs.CurveParameter(line, 0)),
                           90, [0, 0, 1])
    norm = rs.VectorScale(rs.VectorUnitize(norm), dist)
    sideStPt = rs.VectorAdd(rs.CurveStartPoint(line), norm)
    sideEndPt = rs.VectorAdd(rs.CurveEndPoint(line), norm)
    newLine = rs.AddLine(sideStPt, sideEndPt)
    return newLine
Example #5
0
def getTwoParallelLineSelectionRegion(p0, p1, pi, width):
    lineDirect = rs.VectorUnitize(rs.VectorCreate(p1, p0))
    lineCross = rs.VectorRotate(lineDirect, 90, (0, 0, 1))
    piUp = rs.VectorAdd(pi, rs.VectorScale(lineCross, width))
    piDown = rs.VectorAdd(pi, rs.VectorScale(rs.VectorReverse(lineCross),
                                             width))
    piDownRight = rs.VectorAdd(piDown, lineDirect * width)
    return (geo.Point3d(piUp), geo.Point3d(piDown), geo.Point3d(piDownRight))
Example #6
0
 def ptRun(self):
     self.v = rs.VectorAdd(self.v, self.a)
     v = rs.VectorLength(self.v)
     if v > 15:
         self.v = rs.VectorScale(rs.VectorUnitize(self.v), 15)
     self.p = rs.VectorAdd(self.p, self.v)
     self.a = rs.VectorCreate( (0,0,0),(0,0,0) )
      
     self.ptList.append(self.p)
Example #7
0
 def attractor(self, mag):
      
     attrPt = rs.VectorCreate((-800,-700,0) , (0,0,0))
     steer = rs.VectorCreate( (0,0,0) , (0,0,0) )
     diff = rs.VectorSubtract( attrPt, self.p )
     diff = rs.VectorUnitize(diff)
      
     steer = rs.VectorAdd(steer , diff)
     steer = rs.VectorScale(steer, mag)
       
     self.a = rs.VectorAdd(self.a, steer)
def Shift(res, trim):

    left = []
    right = []

    for j in range(len(res[1])):
        left.append(rs.VectorAdd(res[1][j], [0, 0, -1 * trim]))

    for j in range(len(res[2])):
        right.append(rs.VectorAdd(res[2][j], [0, 0, -1 * trim]))

    return [res[0], left, right]
Example #9
0
def throwNode(nodes,speed,stickRange,passParams,resizeThreshold):
    boundRadius = passParams[0]
    bGeom = passParams[1]
    #sFactor = passParams[2]
    #print passParams[2]
    #assumes time steps of 1
    startPos = getBoundaryPos(boundRadius);
    endPos = getBoundaryPos(boundRadius);
    
    direction = rs.VectorSubtract(endPos,startPos)
    direction = rs.VectorUnitize(direction)
    vel = rs.VectorScale(direction,speed);

    currentPos = rs.VectorAdd(startPos,vel)

    previewGeom = []

    isTravelling = True
    while(isTravelling):
        scriptcontext.escape_test() #hit escape to quit NOT WORKING
        time.sleep(0.01*10**-7)
        for o in previewGeom: rs.DeleteObjects(o)
        dist = rs.VectorLength(currentPos) #distance to origin
        #check if particle went out of bounds
        if(dist>boundRadius):
            isTravelling = False
       
        else:
            previewGeom.append(drawPos(currentPos,stickRange))
            for i in range(len(nodes)):
                n = nodes[i]
                if(inStickRange(currentPos,n,stickRange)):
                    #GOT STUCK! add a new node at that position
                    newNode = node(currentPos,i,.08) #parent is idx of node stuck too
                    newNode.increaseRadius(.01, nodes)
                    nodes.append(newNode)
                    #rNodes.append(rs.AddPoint(currentPos))
                    if(math.fabs(boundRadius-dist) <= resizeThreshold):
                        #print "boundRadius should resize"
                        rs.DeleteObjects(bGeom)
                        boundRadius += resizeThreshold/2 #arbitrary
                        bGeom = rs.AddCircle([0,0,0],boundRadius)
                        passParams[0] = boundRadius
                        passParams[1] = bGeom

                    isTravelling = False
                    for o in previewGeom: rs.DeleteObjects(o)
                    break
            
            currentPos = rs.VectorAdd(currentPos,vel)
        Rhino.RhinoApp.Wait()
        
    return passParams
Example #10
0
def addLevelMarks(func):
    rs.EnableRedraw(False)
    leftAlign = True
    geometry = []
    currentLevels = setLevels.getFloorLevels()
    for level in currentLevels:
        if level is None:
            print "Levels have not been set."
            return
    levelNames = rs.GetDocumentData("Levels")
    size = 10
    i = 0
    stPts = []
    for level in currentLevels:
        vec1 = [size*.2,size*.1,0]
        ptA = [0, level, 0]
        ptB = [size*.5, level, 0]
        stPts.append(ptA)
        geometry.append(rs.AddLine(ptA, ptB))
        geometry.append(rs.AddText(levelNames[i] + ": +" + str(level), rs.VectorAdd(ptA, vec1), size*.1))
                
        #Triangle Marking
        triPts = [[0,0,0], [size*.05, size*.07,0], [-size*.05, size*.07,0], [0,0,0]]
        newPts = []
        triPt = rs.VectorAdd(ptA, [size*.1, 0,0])
        for j in range(0, 4):
            newPts.append(rs.VectorAdd(triPt, triPts[j]))
        tri = rs.AddPolyline(newPts)
        geometry.append(rs.CloseCurve(tri))
        i=i+1
    
    #Dimensions
    for i in range(0, len(currentLevels)-1):
        pt1 = [0,currentLevels[i], 0]
        pt2 = [0,currentLevels[i+1], 0]
        pt3 = [size*-.15,currentLevels[i+1], 0]
        geometry.append(rs.AddAlignedDimension(pt1, pt2, pt3))
    firstPt = [0,currentLevels[0], 0]
    lastPt = [0,currentLevels[-1], 0]
    dimOffset = [size*-.3,currentLevels[-1], 0]
    geometry.append(rs.AddAlignedDimension(firstPt, lastPt, dimOffset))
    rs.AddLayer("80_LAYOUT", visible = True)
    annoLayer = rs.AddLayer("ANNO", parent = "80_LAYOUT")
    for geo in geometry:
        rs.ObjectLayer(geo, annoLayer)
    rs.AddBlock(geometry, [0,0,0], "Level Marks", True)
    if (func == 0):
        block = rs.InsertBlock("Level Marks", [0,0,0])
        rs.ObjectLayer(block, "ANNO")
    
    rs.EnableRedraw(True)
    return
def offsetPoints(pList, startPt, endPt):
    pointList = []
    sideVector = rs.VectorCreate(endPt, startPt)
    pointSpacing = (rs.VectorLength(sideVector) / len(pList))
    gapVector = rs.VectorUnitize(sideVector)
    gapVector = rs.VectorScale(gapVector, pointSpacing)
    for i in range(0, len(pList)):
        scaledVector = rs.VectorScale(gapVector, i)
        pointMove = rs.VectorAdd(startPt, scaledVector)
        offsetPoint = rs.VectorAdd(pointMove,
                                   pList[i] * rs.VectorLength(sideVector))
        point = (0, 0, 0)
        movedPoint = rs.PointAdd(point, offsetPoint)
        pointList.append(movedPoint)
    return pointList
Example #12
0
 def align(self, mag):
       
     steer = rs.VectorCreate( (0,0,0) , (0,0,0) )
     count = 0
       
     for i in pts:
         distance = rs.Distance(i.p, self.p)
         if distance > 0 and distance < 40:
             steer = rs.VectorAdd(steer, i.v)
             count += 1
       
     if count>0:
         steer = rs.VectorScale(steer, 1.0/count)
       
     steer = rs.VectorScale(steer, mag)
     self.a = rs.VectorAdd(self.a, steer)
Example #13
0
def blendcorners():
    polyline_id = rs.GetObject("Polyline to blend", 4, True, True)
    if not polyline_id: return

    vertices = rs.PolylineVertices(polyline_id)
    if not vertices: return

    radius = rs.GetReal("Blend radius", 1.0, 0.0)
    if radius is None: return

    between = lambda a, b: (a + b) / 2.0
    newverts = []
    for i in range(len(vertices) - 1):
        a = vertices[i]
        b = vertices[i + 1]
        segmentlength = rs.Distance(a, b)
        vec_segment = rs.PointSubtract(b, a)
        vec_segment = rs.VectorUnitize(vec_segment)

        if radius < (0.5 * segmentlength):
            vec_segment = rs.VectorScale(vec_segment, radius)
        else:
            vec_segment = rs.VectorScale(vec_segment, 0.5 * segment_length)

        w1 = rs.VectorAdd(a, vec_segment)
        w2 = rs.VectorSubtract(b, vec_segment)
        newverts.append(a)
        newverts.append(between(a, w1))
        newverts.append(w1)
        newverts.append(between(w1, w2))
        newverts.append(w2)
        newverts.append(between(w2, b))
    newverts.append(vertices[len(vertices) - 1])
    rs.AddCurve(newverts, 5)
    rs.DeleteObject(polyline_id)
Example #14
0
def FitSurface(srf_id, samples):
    surf_points = rs.SurfacePoints(srf_id)
    G = rs.SurfaceEditPoints(srf_id, True, True)
    N = GrevilleNormals(srf_id)
    S = ConvertToUVW(srf_id, samples)

    Forces = [(0, 0, 0) for pt in surf_points]
    Factors = [0.0 for pt in surf_points]
    proximity = 0.0
    translation = 0.0

    for i in range(len(S)):
        proximity += abs(S[i][2])
        for j in range(len(surf_points)):
            local_dist = (S[i][0] - G[j][0])**2 + (S[i][1] - G[j][1])**2
            if local_dist < 0.01: local_dist = 0.01
            local_factor = 1 / local_dist
            local_force = rs.VectorScale(N[j], local_factor * S[i][2])
            Forces[j] = rs.VectorAdd(Forces(j), local_force)
            Factors[j] += local_factor

    Forces = DivideVectorArray(Forces, Factors)

    for i in range(len(surf_points)):
        surf_points[i] = rs.PointAdd(surf_points[i], Forces[i])
        translation += rs.VectorLength(Forces[i])

    srf_N = rs.SurfacePointCount(srf_id)
    srf_K = rs.SurfaceKnots(srf_id)
    srf_W = rs.SurfaceWeights(srf_id)
    srf_D = (rs.SurfaceDegree(srf_id, 0), rs.SurfaceDegree(srf_id, 1))
    return rs.AddNurbsSurface(srf_N, P, srf_K[0], srf_K[1], srf_D, srf_W)
Example #15
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 #16
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 #17
0
def orientObjAlongPolyPts(obj, pts, basePoint=(0, 0, 0), baseVect=(0, 1, 0)):
    print('orient obj along poly points')
    up = (0, 0, 1)
    generatedObjects = []
    for i in range(0, len(pts) - 1):

        if i < (len(pts) - 2):
            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)
        else:
            p0 = pts[i]
            p1 = pts[i + 1]
            v1 = rs.VectorUnitize(p1 - p0)
            n = rs.VectorCrossProduct(v1, up)

        rs.AddLine(p1, p1 + n)

        a = rs.VectorAngle((0, 1, 0), n)
        gen = rs.OrientObject(obj, [basePoint, basePoint + baseVect],
                              [p1, p1 + n], 1)
        generatedObjects.append(gen)
        #g=rs.AddGroup()
        #groupObjects=rs.AddObjectsToGroup(generatedObjects,g)
        return generatedObjects
Example #18
0
def offset_face(mesh, fkey, t):

    cent = mesh.face_centroid(fkey)
    vcords = mesh.face_coordinates(fkey, ordered=True)
    vkeys = mesh.face_vertices(fkey, ordered=True)

    pts = []
    vecs = []

    keys = [None] * len(vcords)
    for i, vcor in enumerate(vcords):
        vec1 = rs.VectorUnitize(rs.VectorCreate(vcords[i - 2], vcords[i - 1]))
        vec2 = rs.VectorUnitize(rs.VectorCreate(vcords[i], vcords[i - 1]))
        vec = rs.VectorAdd(vec1, vec2)
        vec = rs.VectorUnitize(vec)
        ang = rs.VectorAngle(vec, vec1)
        ang = math.radians(ang)
        l = t / math.sin(ang)
        vec = rs.VectorScale(vec, l)
        pt = rs.PointAdd(vcords[i - 1], vec)
        keys[i - 1] = mesh.add_vertex(x=pt[0], y=pt[1], z=pt[2])
    for i, vkey in enumerate(vkeys):
        mesh.add_face([vkeys[i], keys[i], keys[i - 1], vkeys[i - 1]])
    mesh.add_face(keys)
    del mesh.face[fkey]
Example #19
0
    def update(self):

        self.vecAcceleration = rs.VectorCreate(self.acceleration,
                                               self.basePoint)
        self.vecVelocity = rs.VectorAdd(self.vecVelocity, self.vecAcceleration)
        self.location = rs.PointAdd(self.location, self.vecVelocity)
        self.acceleration = rs.VectorScale(self.acceleration, 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
def createAirplane():
    #CREATE FUSELAGE
    rectangleFuselage = rs.AddRectangle(rs.WorldXYPlane(), Fw, Fh)
    endPointsF = rs.PolylineVertices(rectangleFuselage)
    fPtsB = offsetPoints(Fpb, endPointsF[0], endPointsF[1])
    fPtsR = offsetPoints(Fpr, endPointsF[1], endPointsF[2])
    fPtsT = offsetPoints(Fpt, endPointsF[2], endPointsF[3])
    fPtsL = offsetPoints(Fpl, endPointsF[3], endPointsF[0])
    fPtsL.append(fPtsB[0])
    fCurveOpen = rs.AddCurve(fPtsB + fPtsR + fPtsT + fPtsL, 2)

    #CREATE WING SLOT
    wingSlotStart = rs.VectorAdd(endPointsF[0], (Fwx, Fwy, 0))
    wingSlotEnd = rs.VectorAdd(wingSlotStart,
                               (Fw - Fwx + maxPointOffset * 2, 0, 0))
    wingSlot = rs.AddLine(wingSlotStart, wingSlotEnd)
    wingSlotOffset = rs.OffsetCurve(wingSlot, (0, 1, 0), 1 / 32)
    rs.AddLine(rs.CurveStartPoint(wingSlot),
               rs.CurveStartPoint(wingSlotOffset))

    #CREATE WING
    wPlaneOffY = Wh + 1
    wPlaneOffX = Fw / 2
    wingPlane = rs.MovePlane(rs.WorldXYPlane(), (wPlaneOffX, -wPlaneOffY, 0))
    rectangleWing = rs.AddRectangle(wingPlane, Ww, Wh)
    endPointsW = rs.PolylineVertices(rectangleWing)
    wPtsB = offsetPoints(Wpb, endPointsW[0], endPointsW[1])
    wPtsR = offsetPoints(Wps, endPointsW[1], endPointsW[2])
    wPtsT = offsetPoints(Wpt, endPointsW[2], endPointsW[3])
    wPtsT.append(endPointsW[3])
    wPtsB.insert(0, endPointsW[0])
    wingCurve = rs.AddCurve(wPtsB + wPtsR + wPtsT)
    #wingLine = rs.AddLine(endPointsW[3],endPointsW[0])
    rs.MirrorObject(wingCurve, endPointsW[3], endPointsW[0], True)

    #CREATE WING GROOVE
    wingGrooveStart = rs.VectorAdd(endPointsW[3], (-1 / 64, maxPointOffset, 0))
    wingGrooveEnd = rs.VectorAdd(wingGrooveStart,
                                 (0, -(maxPointOffset + Wh * Wsd), 0))
    wingGroove = rs.AddLine(wingGrooveStart, wingGrooveEnd)
    wingGrooveOffset = rs.OffsetCurve(wingGroove, (1, 0, 0), -1 / 32)
    rs.AddLine(rs.CurveEndPoint(wingGroove),
               rs.CurveEndPoint(wingGrooveOffset))

    #DELETE RECTANGLES
    rs.DeleteObject(rectangleFuselage)
    rs.DeleteObject(rectangleWing)
def get_addition_columns(a,b):
    sq2 = math.sqrt(2.0)
    if a<ra and b<ra:
        p = rg.Vector2d(a,b)
        columnradius = ra * sq2 / ((n-1) * 2 + sq2)
        p = rot45(p)
        p = rs.VectorSubtract(p,rg.Vector3d(sq2 / 2 * ra,0,0))
        p = rs.VectorAdd(p,rg.Vector3d(columnradius*sq2,columnradius*sq2,0))
        if n%2==1:
            p = rs.VectorAdd(p,rg.Vector3d(0,columnradius,0))
        p.Y = mod1(p.Y, columnradius*2)
        result = p.Length-columnradius
        result = min(result, p.X)
        result = min(result, a)
        return min(result, b)
    else:
        return min(a,b)
Example #23
0
 def draw_lpoint_triple(text, tail, head):
     """Receives label text and a list of point triples:
         str
         [<iter>, ...]
     Draws text dots with <text>-a, -b, -c
     """
     line_vector = rs.PointSubtract(head, tail)
     offset_vector = line_vector * offset
     offset_tail = rs.VectorAdd(tail, offset_vector)
     offset_head = rs.VectorSubtract(head, offset_vector)
     axis = [0, 0, 1]
     angle = 90
     rotated_offset_vector = rs.VectorRotate(offset_vector, angle, axis)
     offset_side = rs.VectorAdd(offset_tail, rotated_offset_vector)
     rs.AddTextDot(('%s-a' % text), offset_tail)
     rs.AddTextDot(('%s-b' % text), offset_head)
     rs.AddTextDot(('%s-c' % text), offset_side)
Example #24
0
 def cohesion(self, mag):
       
     sum = rs.VectorCreate( (0,0,0) , (0,0,0) )
     count = 0
       
     for i in pts:
         distance = rs.Distance(i.p, self.p)
         if distance > 0 and distance < 60:
             sum = rs.VectorAdd(sum, i.p)
             count += 1
       
     if count>0:
         sum = rs.VectorScale(sum, 1.0/count)
       
     steer = rs.VectorSubtract(sum, self.p)
     steer = rs.VectorScale(steer, mag)
     self.a = rs.VectorAdd(self.a, steer)
Example #25
0
def Main():

    jointno = 4

    list = []

    dir0 = rs.GetPoint("from")
    dir1 = rs.GetPoint("hub")
    dir2 = rs.GetPoints(False, False, "outline_left_to_right")

    #THIS VECTOR WILL ALLOW US TO TAKE INTO ACCOUNT POSSIBLE LAYOUT OF DRAWN JOINTS ON THE PAGE
    fix = rs.VectorSubtract([0, 0, 0], dir1)

    dir0 = rs.VectorAdd(dir0, fix)
    dir1 = rs.VectorAdd(dir1, fix)
    indir = rs.VectorSubtract(dir1, dir0)

    for j in range(len(dir2)):
        pt = rs.VectorAdd(dir2[j], fix)
        dir2[j] = pt

    list.append([dir1, indir, dir2])

    for i in (range(jointno)[1:]):

        dir0 = rs.GetPoint("from")
        dir1 = rs.GetPoint("hub")
        dir2 = rs.GetPoint("to")

        #THIS VECTOR WILL ALLOW US TO TAKR INTO ACCOUNT POSSIBLE LAYOUT OF DRAWN JOINTS ON THE PAGE
        fix = rs.VectorSubtract([0, 0, 0], dir1)

        #What is this line doing???
        dir0 = rs.VectorAdd(dir0, fix)
        dir1 = rs.VectorAdd(dir1, fix)
        dir2 = rs.VectorAdd(dir2, fix)

        #Setting up direction vectors!
        indir = rs.VectorSubtract(dir1, dir0)
        outdir = rs.VectorSubtract(dir2, dir1)

        lside = rs.GetPoints(False, False, "left")
        rside = rs.GetPoints(False, False, "right")

        for j in range(len(lside)):
            pt = rs.VectorAdd(lside[j], fix)
            lside[j] = pt

        for j in range(len(rside)):
            pt = rs.VectorAdd(rside[j], fix)
            rside[j] = pt

        list.append([dir1, indir, lside, rside, outdir])

    WritePolies(addresss, list)
Example #26
0
def get_arc_rod_points(pntI, pntJ, radius, reverse):
    '''
         D ------------------E
       /
      C--I------------------>J
       \ 
         B ------------------A
    reverse will reverse order of points depicted above
    '''
    offset = -1.0 * radius
    pntB, pntC, pntD = get_arc_cap(pntI, pntJ, offset, radius)
    vec_A = get_sized_perpendicular_vector(pntI, pntJ, radius, left=False)
    pntA = rs.VectorAdd(pntJ, vec_A)
    vec_E = get_sized_perpendicular_vector(pntI, pntJ, radius, left=True)
    pntE = rs.VectorAdd(pntJ, vec_E)
    pnts = [pntA, pntB, pntC, pntD, pntE]
    if reverse: pnts.reverse()
    return pnts
Example #27
0
def LocationMesh(origin, basis):
    points = UnitBasis()
    # Convert directions to positions relative to origin
    for b in range(3):
        points[b] = rs.VectorAdd(basis[b], origin)
    # Construct basis tetrahedron
    mesh = rs.AddMesh([origin, points[0], points[1], points[2]],
                      [[0, 2, 1], [0, 3, 2], [0, 1, 3], [1, 2, 3]])
    return mesh
Example #28
0
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
Example #29
0
def growRegion():
    filter = Rhino.DocObjects.ObjectType.Mesh
    rc, objRef = Rhino.Input.RhinoGet.GetOneObject("select testMesh", False,
                                                   filter)
    if not objRef or rc != Rhino.Commands.Result.Success: return rc
    mesh = objRef.Mesh()
    if not mesh: return
    mesh.Compact()

    randIdx = int(random.uniform(0, mesh.Vertices.Count - 1))
    tVertIdxRoot = mesh.TopologyVertices.TopologyVertexIndex(randIdx)
    vertPnt = mesh.Vertices[randIdx]
    rad = .1
    rs.AddSphere(vertPnt, rad)

    growVerts = []

    stepSize = .01
    maxGrowLen = .5
    minGrowLen = .02
    cutoffDist = .7
    gKernel = GKernel(stepSize, maxGrowLen, minGrowLen, cutoffDist)
    gKernel.plot()

    conVertsIdx = mesh.Vertices.GetConnectedVertices(randIdx)
    print type(conVertsIdx)
    #conVertsIdx is an Array[int] in .NET framework.
    print str(conVertsIdx.Length)
    for i in range(conVertsIdx.Length):
        idx = conVertsIdx[i]
        if (idx != randIdx):
            tVertIdx = mesh.TopologyVertices.TopologyVertexIndex(idx)
            dist = lenBetweenTVerts(tVertIdxRoot, tVertIdx, mesh)
            lookUpIdx = int(round(dist / stepSize))
            distStr = "d:%1.2f,i:%d" % (dist, lookUpIdx)
            rs.AddTextDot(distStr, mesh.Vertices[idx])
            if (dist < cutoffDist):
                growVerts.append([idx, lookUpIdx])
        else:
            growVerts.append([idx, 0])
    """GROW REGION"""
    for i in range(len(growVerts)):
        vertIdx = growVerts[i][0]
        kernelIdx = growVerts[i][1]
        growLength = gKernel.gaussKernel[kernelIdx]

        vert = mesh.Vertices[vertIdx]
        vertNormal = mesh.Normals[vertIdx]
        growVec = vertNormal.Multiply(vertNormal, growLength)
        newLoc = rs.VectorAdd(vert, growVec)

        #normalArrow = rs.AddLine(vert,newLoc)
        #rs.CurveArrows(normalArrow,2)

        mesh.Vertices.SetVertex(vertIdx, newLoc.X, newLoc.Y, newLoc.Z)
        scriptcontext.doc.Objects.Replace(objRef, mesh)
def plineCoordinate(pline):
    ctrlPts = rs.CurvePoints(pline)
    offsetDist = 3
    offsetVec = [offsetDist, offsetDist, 0]
    textVec = [offsetDist, 0, 0]
    for ctrlPt in ctrlPts:
        leaderList = []
        ptX = ctrlPt[0]
        ptY = ctrlPt[1]
        ptZ = ctrlPt[2]
        text = str(ptX) + ", " + str(ptY) + ", " + str(ptZ)
        leaderPt = rs.VectorAdd(ctrlPt, offsetVec)
        textPt = rs.VectorAdd(leaderPt, textVec)
        leaderList.append(ctrlPt)
        leaderList.append(leaderPt)
        leaderList.append(textPt)
        leader = rs.AddLeader(leaderList, text=text)
        root = rs.AddLayer("80_LAYOUT")
        dimsLayer = rs.AddLayer("LEADERS", parent=root, color=(200, 200, 200))
        rs.ObjectLayer(leader, dimsLayer)