Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lm = mag(p2 - p1)
if (lm < L):
L = lm
r = L * roundness # radius of rounded curve connecting adjacent sides
ncp = [[0,0]] # starting point will be modified later
for i in range(lcp):
v1 = cp[(i+1) % lcp] - cp[i % lcp] # first side
v2 = cp[(i+2) % lcp] - cp[(i+1) % lcp] # next side
theta = v1.diff_angle(v2) # angle of change of direction from first side to next side
d = r*tan(theta/2) # how much to shorten the end of a side and the start of the next
p1 = cp[i] + v1 - d*norm(v1) # end of first side, start of bend
p2 = cp[(i+1) % lcp] + d*norm(v2) # start of next side, end of bend
ncp.append([p1.x, p1.y])
N = norm(v1).cross(norm(v2))
center = p1 + r*norm(N.cross(v1)) # center of circular arc
v = p1 - center
dtheta = theta/(nseg+1)
if N.z < 0: dtheta = -dtheta
if invert:
c = 0.5*(p1 + p2) # midpoint along line connecting p1 and p2
center = c + (c-center) # move center to other side of corner
v = p1 - center
dtheta = -dtheta
for j in range(nseg):
v1 = center + v.rotate(j*dtheta)
ncp.append([v1.x, v1.y])
ncp.append([p2.x, p2.y])
def line(self, pos=[0,0], width=1, height=None, np=2, rotate=0, thickness=None,
start=[0,0], end=[0,1], scale=1, xscale=1, yscale=1):
v = vec(end[0] - start[0], end[1] - start[1], 0)
if thickness is None: thickness = .01 * mag(v)
dv = thickness * norm(vec(0, 0, 1).cross(v))
dx = dv.x
dy = dv.y
cp = [] # outer line
cpi = [] # inner line
vstart = vec(start[0], start[1], 0)
v = vec(end[0]-start[0], end[1]-start[1], 0)
vline = v/(floor(np-1))
for i in range(np):
v = i*vline
x = start[0] + v.x
y = start[1] + v.y
cp.append([x + pos[0], y + pos[1]])
cpi.append([x + pos[0] + dx, y + pos[1] + dy])
cpi.reverse()
for i in range(len(cpi)): cp.append(cpi[i])
def convert(pos=(0,0,0), up=(0,1,0), points=None, closed=True):
pos = vector(pos)
up = norm(vector(up))
up0 = vector(0,1,0)
angle = acos(up.dot(up0))
reorient = (angle > 0.0)
axis = up0.cross(up)
pts = []
for pt in points:
newpt = vector(pt[0],0,-pt[1])
if reorient: newpt = newpt.rotate(angle=angle, axis=axis)
pts.append(pos+newpt)
if closed and not pts[-1].equals(pts[0]): pts.append(pts[0])
return pts
if (lm < L):
L = lm
r = L * roundness # radius of rounded curve connecting adjacent sides
ncp = [[0,0]] # starting point will be modified later
for i in range(lcp):
v1 = cp[(i+1) % lcp] - cp[i % lcp] # first side
v2 = cp[(i+2) % lcp] - cp[(i+1) % lcp] # next side
theta = v1.diff_angle(v2) # angle of change of direction from first side to next side
d = r*tan(theta/2) # how much to shorten the end of a side and the start of the next
p1 = cp[i] + v1 - d*norm(v1) # end of first side, start of bend
p2 = cp[(i+1) % lcp] + d*norm(v2) # start of next side, end of bend
ncp.append([p1.x, p1.y])
N = norm(v1).cross(norm(v2))
center = p1 + r*norm(N.cross(v1)) # center of circular arc
v = p1 - center
dtheta = theta/(nseg+1)
if N.z < 0: dtheta = -dtheta
if invert:
c = 0.5*(p1 + p2) # midpoint along line connecting p1 and p2
center = c + (c-center) # move center to other side of corner
v = p1 - center
dtheta = -dtheta
for j in range(nseg):
v1 = center + v.rotate(j*dtheta)
ncp.append([v1.x, v1.y])
ncp.append([p2.x, p2.y])
v1 = cp[1] - cp[0]
p1 = cp[i]
p2 = cp[(i + 1) % lcp]
lm = mag(p2 - p1)
if (lm < L):
L = lm
r = L * roundness # radius of rounded curve connecting adjacent sides
ncp = [[0,0]] # starting point will be modified later
for i in range(lcp):
v1 = cp[(i+1) % lcp] - cp[i % lcp] # first side
v2 = cp[(i+2) % lcp] - cp[(i+1) % lcp] # next side
theta = v1.diff_angle(v2) # angle of change of direction from first side to next side
d = r*tan(theta/2) # how much to shorten the end of a side and the start of the next
p1 = cp[i] + v1 - d*norm(v1) # end of first side, start of bend
p2 = cp[(i+1) % lcp] + d*norm(v2) # start of next side, end of bend
ncp.append([p1.x, p1.y])
N = norm(v1).cross(norm(v2))
center = p1 + r*norm(N.cross(v1)) # center of circular arc
v = p1 - center
dtheta = theta/(nseg+1)
if N.z < 0: dtheta = -dtheta
if invert:
c = 0.5*(p1 + p2) # midpoint along line connecting p1 and p2
center = c + (c-center) # move center to other side of corner
v = p1 - center
dtheta = -dtheta
for j in range(nseg):
v1 = center + v.rotate(j*dtheta)
ncp.append([v1.x, v1.y])