示例#1
0
def _p5_circleArcOP2(arc, style):
    if arc == None:
        return None
    if arc.disk.a == 0:
        return _p5_segmentE2(
            SegmentE2(
                arc.source.toPointE2(),
                arc.target.toPointE2()
            ), 
            style
        )
    else:
        rad = arc.radius
        
        srcOP2, trgOP2 = (arc.source, arc.target) if arc.disk.a >= 0 else (arc.target, arc.source)
        src, trg = srcOP2.toPointE2(), trgOP2.toPointE2()
        
        ratio = math.sqrt(src.distTo(trg)) / rad
        
        if ratio < 0.1:
            return _p5_segmentE2(
                SegmentE2(
                    arc.source.toPointE2(),
                    arc.target.toPointE2()
                ), 
                style
            )
        else: 
            radInv = 1.0 / rad
            center = arc.disk.center.toPointE2()
            
            srcV = VectorE2((src.x - center.x) * radInv, (src.y - center.y) * radInv)
            trgV = VectorE2((trg.x - center.x) * radInv, (trg.y - center.y) * radInv)

            srcAngle = srcV.angleFromXAxis()
            targetAngle = trgV.angleFromXAxis()
            
            if srcAngle > targetAngle:
                targetAngle += 2.0 * math.pi
            
            result = {"type": "CircleArcE2", 
                      "center": tuple(center), 
                      "radius": rad,
                      "srcAngle": srcAngle, 
                      "targetAngle": targetAngle}
            
            if style == None:
                result["style"] = makeStyle(stroke = "#000", strokeWeight = 1)
                
            return result
示例#2
0
def TutteEmbeddedTilingViewer(tiling,
                              tutteGraph,
                              edgeStyle=makeStyle(stroke="#0375b4",
                                                  strokeWeight=0.5),
                              shadedLevel=-1,
                              style_fn=random_fill,
                              showVertices=False):

    from koebe.geometries.euclidean2 import SegmentE2, PolygonE2

    for vIdx in range(len(tiling.verts)):
        tiling.verts[vIdx].idx = vIdx

    viewer = UnitScaleE2Sketch()

    if shadedLevel != -1 and shadedLevel < len(tiling.faceLevels):
        faces = (tiling.faceLevels[shadedLevel]
                 if shadedLevel < len(tiling.faceLevels) else tiling.faces)
        for i in range(1, len(faces)):
            faces[i].idx = i
            style = style_fn(faces[i])
            for tile in collectFaces(faces[i]):
                viewer.add(
                    PolygonE2([
                        tutteGraph.verts[v.idx].data for v in tile.vertices()
                    ]), style)

    viewer.addAll([(SegmentE2(e.aDart.origin.data,
                              e.aDart.twin.origin.data), edgeStyle)
                   for e in tutteGraph.edges])

    if showVertices: viewer.addAll([v.data for v in tutteGraph.verts])

    return viewer
示例#3
0
def _p5_dict(obj, style):
    
    if type(obj) is Vertex:
        obj = obj.data    
    if type(obj) is PointE2:
        result = _p5_pointE2(obj)
    elif type(obj) is PointH2:
        result = _p5_pointE2(obj.toPointE2())
    elif type(obj) is PointOP2:
        result = _p5_pointE2(obj.toPointE2())
    elif type(obj) is CircleE2:
        result = _p5_circleE2(obj, style)
    elif type(obj) is CircleH2:
        result = _p5_circleE2(obj.toPoincareCircleE2(), style)
    elif type(obj) is DiskOP2:
        result = _p5_circleE2(obj.toCircleE2(), style)
    elif type(obj) is DCEL:
        result = _p5_dcel(obj, style)
    elif type(obj) is Edge:
        result = _p5_edge(obj, style)
    elif type(obj) is Face:
        result = _p5_face(obj, style)
    elif type(obj) is CircleArcOP2:
        result = _p5_circleArcOP2(obj, style)
    elif type(obj) is SegmentE2:
        result = _p5_segmentE2(obj, style)
    elif type(obj) is SegmentOP2:
        result = _p5_segmentE2(SegmentE2(obj.source.toPointE2(), 
                                         obj.target.toPointE2()), style)
    elif type(obj) is SegmentH2:
        result = _p5_circleArcOP2(obj.toPoincareCircleArcOP2(), style)
    elif type(obj) is LineH2:
        result = _p5_circleArcOP2(obj.toPoincareCircleArcOP2(), style)
    elif type(obj) is PolygonE2:
        result = _p5_polygonE2(obj, style)
    else:
        result = None
        
    if result != None and style != None:
        result["style"] = style
        
    return result
示例#4
0
 def SegmentE2For(dart):
     return SegmentE2(PointE2For(dart.origin), PointE2For(dart.dest))
示例#5
0
 def pointSegmentE2For(dart):
     return SegmentE2(mvPt(dart.origin.point), mvPt(dart.dest.point))