Ejemplo n.º 1
0
def _make_others():
    p13 = (10, 30, 0)
    p53 = (50, 30, 0)
    diam = 0.5
    s13 = rs.AddSphere(p13, diam)
    s53 = rs.AddSphere(p53, diam)
    return [s13, s53]
def addSphereAtEnds():
    objs = rs.GetObjects("select lines to convert to lights:", rs.filter.curve)
    if objs:
        rs.Prompt("got Objects")
        rs.EnableRedraw(False)
        for obj in objs:
            rs.Prompt("Adding Sphere for obj " + str(obj))
            endPoint = rs.CurveEndPoint(obj)
            startPoint = rs.CurveStartPoint(obj)
            rs.AddSphere(endPoint, SPHERE_RADIUS)
            rs.AddSphere(startPoint, SPHERE_RADIUS)
        rs.EnableRedraw(True)
Ejemplo n.º 3
0
def createSphere():
    sphereRadius = rs.GetReal(message='Of what radius? ', minimum=0.1)
    x, y, z = [float(n) for n in raw_input('where?: "x y z"').split()]
    id = rs.AddSphere((x, y, z), sphereRadius)
    spheres.append(id)
    rs.SetUserText(id, key="Sphere", value=str(len(spheres)))
    print('Done.')
def SamplePointsOnSphere():
    samples = rs.GetInteger("Number of points", 10, 1)
    if samples is None: return
    rs.EnableRedraw(False)
    rs.AddSphere([0, 0, 0], 1)
    rs.AddPoints(GetPointsEquiAngularlyDistancedOnSphere(samples))
    rs.EnableRedraw(True)
def NewSphere(center, radius):
    newsphere = rs.AddSphere(center, radius)
    newsphere = rs.RebuildSurface(newsphere, pointcount=(6, 6))
    rs.n
    materialIndex = rs.AddMaterialToObject(newsphere)
    rs.MaterialColor(materialIndex, (random.uniform(
        0, 50), random.uniform(0, 50), random.uniform(50, 255)))
Ejemplo n.º 6
0
def ImportPoints():
    #prompt the user for a file to import
    filter = "Text file (*.txt)|*.txt|All Files (*.*)|*.*||"
    filename = rs.OpenFileName("Open Point File", filter)
    if not filename: return

    #read each line from the file
    file = open(filename, "r")
    contents = file.readlines()
    file.close()

    # local helper function
    def __point_from_string(text):
        items = text.strip("()\n").split(",")
        center_x = float(items[0])
        center_y = float(items[1])
        r = float(items[2])
        return center_x, center_y, r

    for entry in contents:
        if entry != "&\n":
            info = __point_from_string(entry)
            center = (info[0], info[1])
            radius = info[2]
            rs.AddSphere(center, radius)
Ejemplo n.º 7
0
def offsetCrvEndPt(curve, dist):
    startPt = rs.CurveStartPoint(curve)
    endPt = rs.CurveEndPoint(curve)
    startSphere = rs.AddSphere(startPt, dist)
    endSphere = rs.AddSphere(endPt, dist)
    #intersect sphere with end
    tupStart = rs.CurveSurfaceIntersection(curve, startSphere)
    tupEnd = rs.CurveSurfaceIntersection(curve, endSphere)

    ptSt = rs.AddPoint(tupStart[0][1])
    ptEn = rs.AddPoint(tupEnd[0][1])

    rs.DeleteObject(startSphere)
    rs.DeleteObject(endSphere)

    return (ptSt, ptEn)
def SampleFibonacciSphere():
    samples = rs.GetInteger("Number of points", 10, 1)
    if samples is None: return
    rs.EnableRedraw(False)
    rs.AddSphere([0, 0, 0], 1)
    rs.AddPoints(FibonacciSphere(samples))
    rs.EnableRedraw(True)
Ejemplo n.º 9
0
def makeFirstLevel(_num):
    for x in range(_num):
        for y in range(_num):
            if random.random() > 0.1:
                newPt = rs.CreatePoint((x, y, 0))
                rs.AddSphere(newPt, 1.0)
                pts.append(newPt)
    return pts
Ejemplo n.º 10
0
    def draw_sphere(self, outer_sphere=True):
        sphere = rs.AddSphere(self.center_coordinate, self.radius)

        # Layer割り当て
        if outer_sphere:
            set_layer(sphere, "outer_sphere", 0, 0, 0)
        else:
            set_layer(sphere, "spatial_domain_sphere", 255, 0, 0)
def a():
    a = (1, 0, 0)
    b = (5, 0, 5)
    c = (2, 0, 10)
    d = (10, 0, 15)
    curve = rs.AddCurve((a, b, c, d), 5)
    axis = ((0, 0, 0), (0, 0, 10))
    rs.AddRevSrf(curve, axis, 0, 360)
    rs.AddSphere((0, 0, 12), 3)
def g():
    """
    receives:
        theta = degree of line ( 0 < theta < 45 ) 
        num = number of pattern ( 0 < num < 15 )
    works:
        draw wire
    returns:
        None
    """
    r = 10
    sp = rs.AddSphere((0, 0, 0), r)
    box = []
    for x in rs.frange(-r, r, 0.1):
        for y in rs.frange(-r, r, 0.1):
            if r**2 > x**2 + y**2:
                z = ma.sqrt(abs(r**2 - x**2 - y**2))
                box.append((x, y, z))
        for y in rs.frange(-r, r, 0.1):
            if r**2 > x**2 + y**2:
                z = ma.sqrt(abs(r**2 - x**2 - y**2))
                box.append((x, -y, -z))
    ll = len(box)
    rbox = []
    for i in range(0, ll):
        r = rd.random()
        if r < 0.01:
            rbox.append(box[i])

    box2 = []
    box2.append(rd.sample(box, 300))

    box3 = []
    """
    for i in range(0,100):
        if i == 0:
            dis=[]
            dis2=[]
            for k in range(1,100):
                x =  box2[0][0][0]
                y =  box2[0][0][1]
                z =  box2[0][0][2]
                xx = box2[0][k][0]
                yy = box2[0][k][1]
                zz = box2[0][k][2]
                d = (x-xx)**2 + (y-yy)*2 + (z-zz)**2
                dis.append(d)
                dis2.append(d)
            box2.remove(box2[0][0])
            dis.sort()
            n = dis2.index(dis[-1])
            k = box2[n]
            box2.remove(k)
    """
    curve = rs.AddCurve(rbox, 2)
    rs.AddPipe(curve, 0, 0.05, True)
Ejemplo n.º 13
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 jump(self, magnitude):
     a = rs.PointCoordinates(self.point)
     p = rs.AddPoint(a)
     sphere = rs.AddSphere(p, 4)
     print self.direction
     prevPos = rs.PointCoordinates(self.point)
     for i in range(1, 110):
         rs.MoveObject(sphere, (1, 0, 20 / i))
     for i in range(1, 110):
         rs.MoveObject(sphere, (1, 0, -1 * i / 40))
Ejemplo n.º 15
0
 def inter_S_B(s, div, Lis, br):
     udiv = div
     vdiv = div
     srf = rs.AddSphere((s[1]), ((s[2]) * 2.5))
     u = rs.SurfaceDomain(srf, 0)
     v = rs.SurfaceDomain(srf, 1)
     pts = []
     for i in range(0, udiv + 1, 1):
         for j in range(0, vdiv + 1, 1):
             pt = (i / udiv, j / vdiv, 0)
             srfP = rs.SurfaceParameter(srf, pt)
             newpt = rs.EvaluateSurface(srf, srfP[0], srfP[1])
             pts.append(rs.AddPoint(newpt))
     lig = []
     lid = []
     for p in pts:
         lig.append(rs.AddLine((Lis[0])[1], p))
         lid.append(rs.AddLine((Lis[0])[2], p))
     ig = []
     id = []
     for i in lig:
         for u in br:
             if type(rs.CurveBrepIntersect(i, (u[0]))) == tuple:
                 ig.append((rs.CurveBrepIntersect(i, (u[0]))) +
                           (u[1], ))
             else:
                 ig.append((rs.CurveBrepIntersect(i, (u[0]))))
     for i in lid:
         for u in br:
             if type(rs.CurveBrepIntersect(i, (u[0]))) == tuple:
                 id.append((rs.CurveBrepIntersect(i, (u[0]))) +
                           (u[1], ))
             else:
                 id.append((rs.CurveBrepIntersect(i, (u[0]))))
     if len(id) == 0:
         self.AddRuntimeMessage(
             war,
             "it doesn't seem like there's any geometries connected")
         raise Exception('noGeo')
     intg = 0
     for i in ig:
         if type(i) is tuple:
             intg += (1 * (i[-1]))
     intd = 0
     for i in id:
         if type(i) is tuple:
             intd += (1 * (i[-1]))
     difg = len(ig) - intg
     if difg <= 0:
         difg = 0.1
     difd = len(id) - intd
     if difd <= 0:
         difd = 0.1
     return [(((math.log10(difg * 100 / len(ig))) * 35.3) - 70.6),
             (((math.log10(difd * 100 / len(id))) * 35.3) - 70.6)]
Ejemplo n.º 16
0
def draw_lpoint():
    prompt_for_label = 'Enter the label'
    text = rs.GetString(prompt_for_label)
    prompt_for_point = 'Select the point'
    point = rs.GetPoint(prompt_for_point)
    height = 2
    lpoint = rs.AddText(text, point, height)
    radius = 0.5
    sphere = rs.AddSphere(point, radius)
    group = rs.AddGroup()
    rs.AddObjectsToGroup([lpoint, sphere], group)
Ejemplo n.º 17
0
def init():
    global dictPointByNum  #all the global vars
    global dictPointByCord
    global cvBaseCurve
    global sfBaseSurface
    global reRadius
    global reBase
    global reDist
    global ltObjectPoint
    ptStartPoint = rs.GetObject("Select the point to start", rs.filter.point)
    ptcordStartPoint = rs.PointCoordinates(ptStartPoint)
    rs.AddTextDot("0,0", ptcordStartPoint)
    quePoint = Queue.Queue(maxsize=0)
    quePoint.put(ptcordStartPoint)
    dictPointByNum[(0, 0)] = ptcordStartPoint
    dictPointByCord[ptcordStartPoint] = (0, 0)
    cvBaseCurve = rs.GetObject("Select the baseline", rs.filter.curve)
    sfBaseSurface = rs.GetObject("Select the base surface", rs.filter.surface)
    if sfBaseSurface is None:
        print "what the f**k"
        return -1
    while quePoint.qsize() > 0:
        print quePoint.qsize()  #debug output
        '''

		intContinueResult = continue_or_not()

		if intContinueResult is False:
			return -1
		rs.GetObject("Surface",rs.filter.surface)
		'''

        ptcordTmpPoint = quePoint.get()
        spTmpSphere = rs.AddSphere(ptcordTmpPoint, reBase)
        ltTmpIntersection = rs.CurveSurfaceIntersection(
            cvBaseCurve, spTmpSphere)
        if ltTmpIntersection is None:
            print "the start point should be on the baseline"
            return -1
        ltTmpCordNum = dictPointByCord[ptcordTmpPoint]
        for ltIntersectionPoint in ltTmpIntersection:
            if ltIntersectionPoint[0] == 1:
                ptcordTmpPointInter = ltIntersectionPoint[1]
                boolInOrNot = InOrOut(ptcordTmpPointInter)
                if boolInOrNot == 0:
                    quePoint.put(ptcordTmpPointInter)
                    AddPoint(ptcordTmpPointInter, ptcordTmpPoint, ltTmpCordNum,
                             0)
            else:
                print "Impossible"
                return -1
        rs.DeleteObject(spTmpSphere)

    return 0
Ejemplo n.º 18
0
def createMarkSphere(curve_list):

    curve = curve_list[0]

    domain = rs.CurveDomain(curve)
    t = domain[1] / 2.0
    point = rs.EvaluateCurve(curve, t)

    mark_collision = rs.AddSphere(point, 40)
    rs.ObjectColor(mark_collision, [255, 0, 0])

    return mark_collision
 def jumps(self, magnitude):
     a = rs.GetPoint("Enter start point")
     p = rs.AddPoint(a)
     sphere = rs.AddSphere(p, 4)
     print self.direction
     prevPos = rs.PointCoordinates(self.point)
     for d in range(1, 50):
         nn = rs.Redraw()
         for i in range(1, 50):
             rs.MoveObject(sphere, (1, 1, 20 / i))
         for i in range(1, 50):
             rs.MoveObject(sphere, (1, 1, -1 * i / 40))
Ejemplo n.º 20
0
def main(point, sphereCenter, sphereRadius, legendBakePar):
    # [this is the main function which will calculate the distances from the "point" to the sphere.]
    # [to do this we need to actually calculate the distances between the "point" and points on a sphere.]
    # [these points on a sphere can be vertices of a mesh created from that sphere. So we will first create a sphere, and then create a mesh from that sphere.]

    # [create a sphere:]
    sphereId = rs.AddSphere(sphereCenter, sphereRadius)
    sphereBrep = rs.coercegeometry(
        sphereId
    )  # ["shpereId" represent and id of a sphere. To get the shpere geometry: we use the "rs.coercegeometry" function:]

    # [create a mesh from sphereBrep. There is no rhinoscriptsyntax function which converts a brep to a mesh, so we have to use RhinoCommon one instead:]
    sphereMesh = Rhino.Geometry.Mesh.CreateFromBrep(
        sphereBrep
    )[0]  # [the "[0]" at the end takes a single mesh, because "Rhino.Geometry.Mesh.CreateFromBrep" returns a list]

    # [now we calculate the distances between the "point" and "sphereMesh" vertices:]
    distances = []
    meshVertices = sphereMesh.Vertices  # [get mesh vertices]
    for vertex in meshVertices:
        distance = rs.Distance(
            point, vertex
        )  # [rhinoscriptsyntax function to calculate the distance between a "point" and each mesh vertex]
        distances.append(distance)

    # deconstruct the "legendBakePar_" input to its parts, so that we can use some of them to color the sphereMesh, for title and legend
    legendStyle, legendPlane, maxValue, minValue, customColors, numLegendCells, legendFontName, legendFontSize, numDecimals, legendUnit, customTitle, scale, layerName, layerColor, layerCategoryName = gismo_preparation.read_legendBakePar(
        legendBakePar)

    # [now we color our mesh, according to the upper "ditances" list:]
    meshColors = gismo_preparation.numberToColor(distances, customColors,
                                                 minValue, maxValue)
    coloredSphereMesh = gismo_geometry.colorMeshVertices(
        sphereMesh, meshColors)

    # [that's it! now we can create the "title" and "legend" outputs:]
    # title
    titleLabelText = "Distance between a point and a sphere"  # [this is the text of the title]
    title, titleStartPt, titleTextSize = gismo_preparation.createTitle(
        "mesh", [sphereMesh], [titleLabelText],
        customTitle,
        textSize=legendFontSize,
        fontName=legendFontName)

    # legend
    unitConversionFactor, unitSystemLabel = gismo_preparation.checkUnits()
    legendUnit = unitSystemLabel
    legend, legendPlane = gismo_geometry.createLegend([sphereMesh], distances,
                                                      legendBakePar_,
                                                      legendUnit)

    return distances, sphereMesh, title, legend
def applyVrayMatToLayer(layer, matName):
    """
    applies vray mat to a layer
    input: layer, single layer name - matName: Vray mat string e.g. /glass_architectural
    returns: None
    """
    srf = rs.AddSphere([0,0,0], 1)
    rs.SelectObject(srf)
    rs.Command("-_visApplyMaterial "+matName)
    matIndex = rs.ObjectMaterialIndex(srf)
    rs.LayerMaterialIndex(layer, matIndex)
    rs.DeleteObject(srf)
    return None
Ejemplo n.º 22
0
def followingLines(currentLine, quantity, y, count):
    myPoints = []
    for point in currentLine:
        print point.X
        myTempPoint = rs.CreatePoint(
            (point.X, count * quantity, point.Z + random.random() * 2))
        myPoints.append(myTempPoint)

    for point in myPoints:
        rs.AddSphere(point, quantity)
    count = count + 1
    if (count < target):
        followingLines(myPoints, quantity, count, count)
Ejemplo n.º 23
0
def plot_spl(room, spl, frequency):
    spls = [spl[rec][frequency] for rec in spl]
    minspl = min(spls)
    maxspl = max(spls)
    for rec in spl:
        value = spl[rec][frequency]
        pt = room.receivers[rec]['xyz']
        sph = rs.AddSphere(pt, .2)
        rs.ObjectName(sph, str(value))
        i = (((value - minspl) * (1 - 0)) / (maxspl - minspl)) + 0
        color = i_to_rgb(i)
        # print(minspl, maxspl, value, i, color)
        rs.ObjectColor(sph, color)
Ejemplo n.º 24
0
    def RunScript(self, Listener_Location, Direction, Height):

        __author__ = "theomarchal"
        self.Params.Input[
            0].Description = "Location of the listener foots (as a point - Default is set to 0,0,0)"
        self.Params.Input[
            1].Description = "Direction of the listener (in degrees from 0 to 360)"
        self.Params.Input[
            2].Description = "How tall is the listener (default = 1.80)"
        self.Params.Output[
            0].Description = "Listener Geometry, size and direction"
        self.Params.Output[
            1].Description = "Listener Object (plug it into EsquisSons)"
        self.Name = "Listener Point"
        self.NickName = "Listener"
        self.Message = "EsquisSons V3"
        self.Category = "EsquisSons"
        self.SubCategory = "1/ Scene"

        import rhinoscriptsyntax as rs

        LL = Listener_Location
        LD = Direction
        LH = Height

        if LL is None:
            LL = rs.AddPoint(0, 0, 0)
        if LD is None:
            LD = 0
        if LH is None:
            LH = 1.8

        LV = rs.VectorRotate([0, (LH), 0], LD, [0, 0, 1])
        matrix = rs.XformTranslation((0, 0, LH))
        LHp = rs.PointTransform(LL, matrix)
        LV2 = rs.VectorScale((rs.VectorRotate(LV, 90, [0, 0, 1])), 0.5)
        LV3 = rs.VectorScale((rs.VectorRotate(LV, -90, [0, 0, 1])), 0.5)
        T1 = rs.PointTransform(LL, (rs.XformTranslation(LV)))
        Tl = rs.PointTransform(LL, (rs.XformTranslation(LV2)))
        Tr = rs.PointTransform(LL, (rs.XformTranslation(LV3)))
        ps = [T1, Tl, Tr]
        Geo = [
            rs.AddSphere(LHp, (LH / 10)),
            rs.AddLine(LL, LHp),
            rs.AddSrfPt(ps)
        ]
        Tl = rs.PointTransform(Tl, matrix)
        Tr = rs.PointTransform(Tr, matrix)
        LP = [LHp, Tl, Tr, LH]
        Listener = [LP]
        return (Geo, Listener)
Ejemplo n.º 25
0
def twistandshout():
    twist_angle = 0.0
    rs.EnableRedraw(False)
    z = 0
    while z <= 5:
        twist_angle += math.pi / 30
        a = 0
        while a < 2 * math.pi:
            x = 5 * math.sin(a + twist_angle)
            y = 5 * math.cos(a + twist_angle)
            rs.AddSphere((x, y, z), 0.5)
            a += math.pi / 15
        z += 0.5
    rs.EnableRedraw(True)
Ejemplo n.º 26
0
def makeLevels(_points, _z, _num, _probability):
    levels = _z
    for point in _points:
        for x in range(_num):
            for y in range(_num):
                currentPt = rs.CreatePoint((x, y, 0))
                if point == currentPt:
                    if random.random() > _probability:
                        newPt = rs.CreatePoint((x, y, _z))
                        rs.AddSphere(newPt, 1.0)
                    else:
                        pts.remove(point)
    levels = levels + 1
    _probability = _probability + 0.2
    if levels < 5:
        makeLevels(lv1, levels, 10, _probability)
    else:
        return False
Ejemplo n.º 27
0
def runSequence1():
    ptCurrent = setOrigin()
    for i in range(0, 30):
        oldpt = rs.AddPoint((ptCurrent[0], ptCurrent[1], ptCurrent[2]))
        addNewPoint = False
        xPoint = getPoint(ptCurrent[0], xPoints)

        if xPoint != 'next':
            ptCurrent[0] = xPoint
            xPoints.append(ptCurrent[0])
            addNewPoint = True

        yPoint = getPoint(ptCurrent[1], yPoints)
        if yPoint != 'next':
            ptCurrent[1] = yPoint
            yPoints.append(ptCurrent[1])
            addNewPoint = True

        if (addNewPoint):
            newPt = rs.MoveObject(oldpt, ptCurrent)
            rs.AddSphere(newPt, 2.0)
            pts.append(ptCurrent)
Ejemplo n.º 28
0
        self.forward(distance)


# Clear the board
rs.DeleteObjects(rs.AllObjects(select=True))

rabbit = Prey()
rabbit.penup()
rabbit.position = Point3d(20, 40, 0)
rabbit.color = Color.Blue
rabbit.pendown()

fox = Predator(8)
fox.color = Color.Red

rabbitIcon = rs.AddSphere(rabbit.position, 0.5)
rs.ObjectColor(rabbitIcon, rabbit.color)
rabbit.decorate(rhinoturtle.Decorator(rabbitIcon))

foxIcon = rs.AddCone(Plane.WorldXY, 2, 1)
rs.ObjectColor(foxIcon, fox.color)
fox.decorate(rhinoturtle.Decorator(foxIcon))

caught = False

while not caught:
    rabbit.wander()
    caught = fox.chase(rabbit)
    rs.Sleep(500)

rs.DeleteObject(rabbitIcon)
    def sphere(self, radius):
        #        a = rs.AddPoint(self.point)
        p = rs.rs.PointCoordinates(self.point)
        a = rs.AddPoint(p)

        box = rs.AddSphere(a, radius)
Ejemplo n.º 30
0
 def sphere(self, radius):
     p = rs.rs.PointCoordinates(self.point)
     a = rs.AddPoint(p)
     box = rs.AddSphere(a, radius)
     rs.DeleteObject(a)