Created
December 15, 2021 22:38
-
-
Save Ichunjo/3dee07c426c8db7854979aaf7a9bea9b to your computer and use it in GitHub Desktop.
interpolate_bezier_curve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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