예제 #1
0
 def drawsilk(self):
     t1 = Curve.DivideByCount(self.flow[0].retrail, 99, True)
     t2 = Curve.DivideByCount(self.flow[1].retrail, 99, True)
     for i in xrange(99):
         pt1 = Curve.PointAt(self.flow[0].retrail, t1[i])
         pt2 = Curve.PointAt(self.flow[1].retrail, t2[i])
         self.silks.append(Line(pt1, pt2))
예제 #2
0
 def drawsimple(self):
     self.trail = Curve.CreateInterpolatedCurve(self.ptlist, 3)
     self.retrail = Curve.Rebuild(self.trail, 30, 3, True)
     self.retrail.Domain = rg.Interval(0, 1)
     crvts = Curve.DivideByCount(self.retrail, 29, True)
     self.reptlist = []
     for i in xrange(len(crvts)):
         self.reptlist.append(Curve.PointAt(self.retrail, crvts[i]))
예제 #3
0
def drawside(crv, sim):
    for i in xrange(len(crv)):
        t = [[], [], [], []]
        for j in xrange(len(crv[i])):
            t[j] = Curve.DivideByCount(crv[i][j], 29, True)
        for k in xrange(len(t[j])):
            pt0 = Curve.PointAt(crv[i][0], t[0][k])
            pt1 = Curve.PointAt(crv[i][1], t[1][k])
            pt2 = Curve.PointAt(crv[i][2], t[2][k])
            pt3 = Curve.PointAt(crv[i][3], t[3][k])
            sim.append(Line(pt0, pt1))
            sim.append(Line(pt2, pt3))
    return sim
예제 #4
0
def RemoveOverlappingCurves(setA,
                            setB,
                            tolerance=0.1):  # doc.ModelAbsoluteTolerance
    '''
    Compare low/high precision Curve sets and remove low precision Cuve when overlapping.

    Parameters:
        setA : list<Rhino.DocObjects.RhinoObject>
            Low precision Curve identifiers
        setB : list<Rhino.DocObjects.RhinoObject>
            High precision Curve identifiers
        tolerance : float
    '''
    for i2, obj1 in enumerate(setA):
        c1 = rs.coercecurve(obj1)

        if c1:
            for i2, obj2 in enumerate(setB):
                c2 = rs.coercecurve(obj2)

                if c2:
                    result = Intersect.Intersection.CurveCurve(
                        c1, c2, tolerance, tolerance)

                    if result:
                        for event in result:
                            if event.IsOverlap:
                                deviation = Curve.GetDistancesBetweenCurves(
                                    c1, c2, tolerance)

                                # minA = deviation[5]
                                maxaA = deviation[2]

                                # maxB = deviation[3]
                                # minB = deviation[6]

                                # minDeviation = deviation[4]
                                maxDeviation = deviation[1]

                                if maxDeviation < tolerance:
                                    l1 = c1.Length if hasattr(
                                        c1, 'Length') else c1.GetLength()
                                    l2 = c2.Length if hasattr(
                                        c2, 'Length') else c2.GetLength()

                                    # Keep if longer otherwise delete low precision Curve
                                    if l1 > l2:
                                        rs.DeleteObject(obj2)
                                    else:
                                        rs.DeleteObject(obj1)
예제 #5
0
파일: drawing.py 프로젝트: elidim/compas
def xdraw_pipes(pipes, cap=2, fit=1.0):
    abs_tol = TOL
    ang_tol = sc.doc.ModelAngleToleranceRadians
    for p in pipes:
        points = p['points']
        radius = p['radius']
        params = [0.0, 1.0]
        cap = ToObject(PipeCapMode, cap)
        if type(radius) in (int, float):
            radius = [radius] * 2
        radius = [float(r) for r in radius]

        rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points])
        breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol,
                                ang_tol)
        for brep in breps:
            yield brep
예제 #6
0
파일: drawing.py 프로젝트: DruidTin/compas
def draw_pipes(pipes, cap=2, fit=1.0):
    """Draw pipes.

    Parameters
    ----------
    pipes : list of dict
        The pipe definitions.

    Other Parameters
    ----------------
    cap : {0, 1, 2}, optional
    fit : float, optional

    Returns
    -------
    list of :class:`Rhino.Geometry.Brep`

    Notes
    -----
    .. code-block:: python

        Schema({
            'points': lambda x: all(len(y) == 3 for y in x),
            'radius': And(Or(int, float), lambda x: x > 0)
        })

    """
    abs_tol = TOL
    ang_tol = sc.doc.ModelAngleToleranceRadians
    for p in pipes:
        points = p['points']
        radius = p['radius']
        params = [0.0, 1.0]
        cap = ToObject(PipeCapMode, cap)
        if type(radius) in (int, float):
            radius = [radius] * 2
        radius = [float(r) for r in radius]

        rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points])
        breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol,
                                ang_tol)
        for brep in breps:
            yield brep
예제 #7
0
파일: drawing.py 프로젝트: elidim/compas
def xdraw_pipes(pipes, cap=2, fit=1.0, **kwargs):
    guids = []
    abs_tol = TOL
    ang_tol = sc.doc.ModelAngleToleranceRadians
    for p in pipes:
        points = p['points']
        radius = p['radius']
        name = p.get('name', '')
        color = p.get('color')
        layer = p.get('layer')
        params = [0.0, 1.0]
        cap = ToObject(PipeCapMode, cap)
        if type(radius) in (int, float):
            radius = [radius] * 2
        radius = [float(r) for r in radius]
        rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points])
        breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol,
                                ang_tol)
        temp = [add_brep(brep) for brep in breps]
        for guid in temp:
            if not guid:
                continue
            obj = find_object(guid)
            if not obj:
                continue
            attr = obj.Attributes
            if color:
                attr.ObjectColor = FromArgb(*color)
                attr.ColorSource = ColorFromObject
            else:
                attr.ColorSource = ColorFromLayer
            if layer and find_layer_by_fullpath:
                index = find_layer_by_fullpath(layer, True)
                if index >= 0:
                    attr.LayerIndex = index
            attr.Name = name
            attr.WireDensity = -1
            obj.CommitChanges()
            guids.append(guid)
    return guids
예제 #8
0
waveflow = []
wavesrf = []
trailsolid = []
silkcollection = []
silklines = []

sidecrv = []  # the side crvs beside tween crvs
sidesim = []

for wave in wavecollection:
    if len(wave.crvlist) == 1:
        trailsolid.append(wave.basecrv)
    elif len(wave.crvlist) == 2:
        wavesrf.append(
            list(Curve.CreateTweenCurves(wave.crvlist[0], wave.crvlist[1], 7)))
        sidecrv.append([
            wave.crvlist[0], wavesrf[-1][0], wavesrf[-1][-1], wave.crvlist[1]
        ])
    elif len(wave.crvlist) >= 3:
        num1 = random.choice(range(len(wave.crvlist)))
        num2 = random.choice(range(len(wave.crvlist)))
        while num1 == num2:
            num2 = random.choice(range(len(wave.crvlist)))
        num3 = random.choice(range(len(wave.crvlist)))
        while num2 == num3 or num1 == num3:
            num3 = random.choice(range(len(wave.crvlist)))
        crv1 = wave.crvlist[num1]
        crv2 = wave.crvlist[num2]
        crv3 = wave.crvlist[num3]
        wavesrf.append(list(Curve.CreateTweenCurves(crv1, crv2, 7)))
예제 #9
0
def draw_pipes(pipes, cap=2, fit=1.0, **kwargs):
    """Draw pipes and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    pipes : list of dict
        A list of pipe dictionaries.

    Other Parameters
    ----------------
    cap : {0, 1, 2}, optional
    fit : float, optional

    Returns
    -------
    list of GUID

    Notes
    -----
    A pipe dict has the following schema:

    .. code-block:: python

        Schema({
            'points': And(list, lambda x: all(len(y) == 3 for y in x)),
            'radius': And(Or(int, float), lambda x: x > 0.0),
            Optional('name', default=''): str,
            Optional('color', default=None): And(lambda x: len(x) == 3, all(0 <= y <= 255 for y in x)),
            Optional('layer', default=None): str,
        })

    """
    guids = []
    abs_tol = TOL
    ang_tol = sc.doc.ModelAngleToleranceRadians
    for p in pipes:
        points = p['points']
        radius = p['radius']
        name = p.get('name', '')
        color = p.get('color')
        layer = p.get('layer')
        params = [0.0, 1.0]
        cap = ToObject(PipeCapMode, cap)
        if type(radius) in (int, float):
            radius = [radius] * 2
        radius = [float(r) for r in radius]
        rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points])
        breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol,
                                ang_tol)
        temp = [add_brep(brep) for brep in breps]
        for guid in temp:
            if not guid:
                continue
            obj = find_object(guid)
            if not obj:
                continue
            attr = obj.Attributes
            if color:
                attr.ObjectColor = FromArgb(*color)
                attr.ColorSource = ColorFromObject
            else:
                attr.ColorSource = ColorFromLayer
            if layer and find_layer_by_fullpath:
                index = find_layer_by_fullpath(layer, True)
                if index >= 0:
                    attr.LayerIndex = index
            attr.Name = name
            attr.WireDensity = -1
            obj.CommitChanges()
            guids.append(guid)
    return guids
예제 #10
0
    def create_segment_contour_edge(self, from_node, to_node,
                                    segment_value, segment_geo):
        """
        Creates a mapping edge between two 'end' nodes in the network. The
        geometry of this edge will be a polyline built from all the given
        former 'weft' edges. returns True if the edge has been successfully
        created.

        Parameters
        ----------
        from_node : :obj:`tuple`
            2-tuple of (node_identifier, node_data) that represents the edges'
            source node.

        to_node : :obj:`tuple`
            2-tuple of (node_identifier, node_data) that represents the edges'
            target node.

        segment_value : :obj:`tuple` of :obj:`int`
            3-tuple that will be used to set the 'segment' attribute of the
            'weft' edge.

        segment_geo : :obj:`list` of :class:`Rhino.Geometry.Line`
            the geometry of all 'weft' edges that make this segment contour
            edge

        Returns
        -------
        success : bool
            ``True`` if the edge has been successfully created,
            ``False`` otherwise
        """

        # get node indices
        fromNode = from_node[0]
        toNode = to_node[0]

        # join geo together
        segment_geo = [RhinoLineCurve(ln) for ln in segment_geo]
        edgeGeo = RhinoCurve.JoinCurves(segment_geo)
        if len(edgeGeo) > 1:
            errMsg = ("Segment geometry could not be joined into " +
                      "one single curve for segment {}!".format(segment_value))
            print(errMsg)
            return False

        edgeGeo = edgeGeo[0].ToPolyline()
        if not edgeGeo[0] == from_node[1]["geo"]:
            edgeGeo.Reverse()

        # create edge attribute
        edgeAttrs = {"warp": False,
                     "weft": False,
                     "segment": segment_value,
                     "geo": edgeGeo}

        self.add_node(fromNode, attr_dict=from_node[1])
        self.add_node(toNode, attr_dict=to_node[1])

        try:
            self.add_edge(fromNode, toNode, attr_dict=edgeAttrs)
        except Exception:
            return False

        return True
예제 #11
0
        heading = Vector3d(u, v, w)

        boid = Boid(boidPoint, heading)
        boids.append(boid)

if run and numSteps:
    print('Flock success!')

    # iteration loop
    for i in range(numSteps):

        # evaluate boids
        for boid in boids:
            boid.findDirection(boids)

        # move boids
        for boid in boids:
            boid.move()

#output points
points = [boid.position for boid in boids]

inclusiveTraces = []
for boid in boids:
    inclusiveTraces.append(
        Curve.CreateControlPointCurve(boid.inclusiveTrail, 3))

exclusiveTraces = []
for boid in boids:
    exclusiveTraces.append(
        Curve.CreateControlPointCurve(boid.exclusiveTrail, 3))