Skip to content

Instantly share code, notes, and snippets.

@Ichunjo
Created December 15, 2021 22:38
Show Gist options
  • Select an option

  • Save Ichunjo/3dee07c426c8db7854979aaf7a9bea9b to your computer and use it in GitHub Desktop.

Select an option

Save Ichunjo/3dee07c426c8db7854979aaf7a9bea9b to your computer and use it in GitHub Desktop.
interpolate_bezier_curve
from typing import List, NamedTuple
import math
class Point(NamedTuple):
x: float
y: float
def interpolate_bezier_curve(curv: List[Point], pct: float) -> Point:
n = len(curv) - 1
def calc_c(c: float, i: int) -> float:
return math.comb(n, i) * (1 - pct) ** (n - i) * pct ** i * c
return Point(*[sum(calc_c(v, i) for i, v in enumerate(coord_zip)) for coord_zip in zip(*curv)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment