Skip to content

Instantly share code, notes, and snippets.

@fullcontrol-xyz
Last active April 18, 2023 21:29
Show Gist options
  • Save fullcontrol-xyz/cfab0b802df07d621d7b5f0494f06505 to your computer and use it in GitHub Desktop.
Save fullcontrol-xyz/cfab0b802df07d621d7b5f0494f06505 to your computer and use it in GitHub Desktop.
from math import radians, degrees
import fullcontrol as fc
import lab.fullcontrol as fclab
def offset_path_gist(points: list, offset: float, flip: bool = False) -> list:
if flip: offset = -offset
offset_lines = []
for i in range(len(points)-1):
line = [points[i], points[i+1]]
line_direction = fc.point_to_polar(line[1], line[0]).angle
offset_line_direction = line_direction + radians(90)
vector = fc.polar_to_vector(offset, offset_line_direction)
offset_lines.append(fc.move(line, vector))
offset_lines = [offset_lines[-1]] + offset_lines + [offset_lines[0]]
intersection_points = []
for i in range(len(offset_lines)-1):
intersection_points.append(fclab.line_intersection_by_points_XY(offset_lines[i][0], offset_lines[i][1], offset_lines[i+1][0], offset_lines[i+1][1]))
return intersection_points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment