Skip to content

Instantly share code, notes, and snippets.

@seanchas116
Created September 10, 2021 11:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanchas116/5b1b5f2d9f5835195afafba83314a3ce to your computer and use it in GitHub Desktop.
Save seanchas116/5b1b5f2d9f5835195afafba83314a3ce to your computer and use it in GitHub Desktop.
Cubic B-spline から ベジエの制御点に変換
export function cubicBSpline(P0: Point, P1: Point, P2: Point, P3: Point): [Point, Point, Point, Point] {
const x0 = (P0[0] + 4 * P1[0] + P2[0]) / 6;
const y0 = (P0[1] + 4 * P1[1] + P2[1]) / 6;
const x1 = (2 * P1[0] + P2[0]) / 3;
const y1 = (2 * P1[1] + P2[1]) / 3;
const x2 = (P1[0] + 2 * P2[0]) / 3;
const y2 = (P1[1] + 2 * P2[1]) / 3;
const x3 = (P1[0] + 4 * P2[0] + P3[0]) / 6;
const y3 = (P1[1] + 4 * P2[1] + P3[1]) / 6;
return [
[x0, y0],
[x1, y1],
[x2, y2],
[x3, y3],
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment