DPath+width bend not ending at 90 degrees

Hello,

This seems like a pretty basic question, but I have been unable to find an answer to it for the past couple of days:

I have been working with non-radial bends lately, by using a DPath and a width value (then converted to a SymplePolygon). However, the end points of the 90 deg bend are not at a perfect 90 deg angle. Is it possible to force the ending point of the resulting Polygon to end at 90 deg?

I have tried to add one last point just above the final point of the bend, which mainly works, but is messing with the length of the curve, so I would need a way to correct or manually set the angle at which the final point of the spine creates the shape.

Thank you in advance!

Comments

  • Hi jviram
    maybe line end extension can provide the result you need

    the pink part is with end extension

  • Hi RawrRanger, thank you for your suggestion.

    The end result is actually somewhat similar to how I have solved this issue so far. I am "manually" adding a point to the list of points, with no variation X, so that the ending angle is at a perfect 90 degree (and it seems to work).

    However, I cannot extend the limit of the bend further than the last point of the path, so I was looking for a way to modify the ending angle of the polygon. Worst case I can just modify the last point instead of adding another, but I feel I am thinking way too much in terms of what python can do, and was wondering if there was a way to handle it through Klayout's functions and tools specifically. Without adding more points or changing the dimensions of the bend, I mean.

  • edited July 2023

    @jviram If you want the line end to be perfect 90 degree, you need to make sure the last segment (the line between the second-last and the last point) is exactly vertical. The end cap is constructed perpendicular to the last segment ("S" in the picture below).

    To achieve this, you can approximate the arc by tangents (outer approximation).

    In addition, the last segment has to be long enough, so the inner side segment ("I" in the picture) does not vanish. This implies a minimum segment length or a maximum resolution of the arc which depends on the width of the path.

    Matthias

  • Is there anything in all this, that depends on the "end type" setting
    in the path creation? Obviously not "round", but maybe "square" vs
    "flush"?

    And then of course the whole Python-script vs menu-pick question,
    for which I've got the usual nuthin'.

  • Hi jviram

    if you don't mind to brute force the line end by pcell, here's an example:
    left side is a path w/o forcing 90 deg
    right side is a path w/ forcing 90 deg
    **increase arc points can improve the smoothness of the arc.

    import pya
    import math
    
    class RightAnglePath(pya.PCellDeclarationHelper):
      def __init__(self):
        super(RightAnglePath, self).__init__()
        self.param("path",         self.TypeLayer,   "Layer",                default = pya.LayerInfo(0, 0))
        self.param("lineWidth",    self.TypeDouble,  "Line width",           default =   4)
        self.param("roundRadius",  self.TypeDouble,  "Path round radius",    default =   10)
        self.param("roundPoints",  self.TypeInt,     "Path round points",    default =   6)
        self.param("bruteForce90", self.TypeBoolean, "Force end Direction ", default =   True)
    
      def display_text_impl(self):
        return "RightAnglePath"
    
      def coerce_parameters_impl(self):
        pass
    
      def can_create_from_shape_impl(self):
        return self.shape.is_box() or self.shape.is_polygon() or self.shape.is_path()
    
      def parameters_from_shape_impl(self):
        self.r = self.shape.bbox().width() * self.layout.dbu / 2
        self.l = self.layout.get_info(self.layer)
    
      def transformation_from_shape_impl(self):
        return pya.Trans(self.shape.bbox().center())
    
      def arc(self, r, p, bruteForce):
        pts  = []
        for i in range(int(p + 1)):
            a = (90 / p * i)/180 * math.pi
            pts.append(pya.DPoint(r * math.cos(a), r * math.sin(a)))
    
        if bruteForce:
            pts[ 1].x = r
            pts[-2].y = r
        return pts  
    
      def produce_impl(self):
        path = pya.DPath(self.arc(self.roundRadius, self.roundPoints, self.bruteForce90), self.lineWidth)
        self.cell.shapes(self.path_layer).insert(path)
    
    
    class temp(pya.Library):
      def __init__(self):
        self.layout().register_pcell("RightAnglePath", RightAnglePath())
        self.description = "temp"
        self.register("temp")
    temp()
    
    
  • Hey!

    Thank you all for your input, it seems I was not too far off with what I was trying. I finally achieved the proper angle thanks to your insight @Matthias, as apparently I was managing to crush the "I" segment and thus not achieving the expected result.

    Also, the code snippet was a blessing, @RawrAngel, as I had not thought of modifying the individual DPoints and was modifying the DPoint list, which ended up being a messier solution. Everything is far more readable now, and I could check I was doing things right.

    Best regards!

  • Hi jviram,
    I just can make some simple code , and here was my code for drawing path.

    viewed_cell.shapes(new_layer).insert(RBA::DPath.new(draw_path_points,pathwidth,(pathwidth / 2.0),(pathwidth / 2.0),1)) 
    

    draw_path_points is what the points list in your path.
    pathwidth means what the width of path.
    as this code , Klayout will create a path with "round" ending.
    Hope that can help you...:)

  • You have Round, Square, Flush and Variable extension
    options in the Path popup. Square will make you a clean
    end, but past where you click. Flush is what gives non-
    ortho straight angles, where you click. No idea what is
    Variable trying to do or why I'd want it - makes its own
    kind of ugly ends, is what I see.

    Probably the best bet is to make Square the default, and
    learn to "stretch to finish" after stopping the path ortho-clean.
    No idea whether you could control the extension "stick-out"
    to make it need less touchup (like, if stickout is less than min
    metal then maybe you just touch the target edge with the
    path final coord, and extension just overlaps a bit and all
    good.

Sign In or Register to comment.