phidl icon indicating copy to clipboard operation
phidl copied to clipboard

phidl.path.transition() with wrong width, offset value make strange shape

Open gyger opened this issue 1 year ago • 1 comments

I don't fully understand the reason but with the following code I get very strange transitions between cross sections, although I think they should be valid.

image

X_1 = phidl.CrossSection()
X_1.add(width = 66, offset = 0, layer = 1, ports = ('in','out'), name="S")
X_1.add(width = 300, offset = 185, layer = 1, name="G1") # (300+66)/2 + 2

X_2 = phidl.CrossSection()
X_2.add(width = 0.08, offset = 0, layer = 1, ports = ('in1','out1'), name="S")
X_2.add(width = 300, offset = 152.04, layer = 1, name="G1") # (300+0.08)/2 + 2

X_trans = pp.transition(cross_section1 = X_1,
                           cross_section2 = X_2,
                           width_type = 'linear')
P2 = pp.straight(length=10)
transition = P2.extrude(X_trans)

Version: '1.6.3'

gyger avatar Mar 24 '23 21:03 gyger

That's a pretty strange transition! I'm guessing the curvature computation is going a little haywire because the amount of curvature is so large in such a small space. These types of offsetting algorithms have difficult when they're asked to make extremely tight turns in short distances. What you're seeing is the inevitability of "cusps" as seen here: https://en.wikipedia.org/wiki/Parallel_curve when turns are made too tight (in this case, the "turn" is actaully the line drawn from "G1" as it's traced out). Note that if you change the transition length to 1000, they dissapear. I'm not sure entirely what to suggest, but you might try overloading the offset function -- right now "sine" and "linear" are built-in, but you could possible make a new function taht would handle this kind of thing in a smart way for this special case. See e.g. Line


def _sinusoidal_transition(y1, y2):
    dx = y2 - y1
    return lambda t: y1 + (1 - np.cos(np.pi * t)) / 2 * dx


def _linear_transition(y1, y2):
    dx = y2 - y1
    return lambda t: y1 + t * dx

amccaugh avatar Apr 17 '23 17:04 amccaugh