export default class BezierCurve {
/**
* 获取贝塞尔曲线的点的集合
* @param points 点的集合, 至少包含起点和终点
* @param num 想要生成多少点
* @returns
*/
public static getCurvePointsInNum(points:Array<any>, num:number): Array<any> {
let result:Array<any> = new Array<any>();
for(let i:number = 0; i < num; i++) {
let t:number = i / (num - 1);
let point = this.getKeyPoint(points, t);
result.push(point);
}
return result;
}
public static getKeyPoint(points: Array<any>, t: number): any {
if (points.length > 1) {
let dirs: Array<any> = new Array<any>();
for (let i: number = 0; i < points.length - 1; i++) {
dirs.push({
x: points[i + 1].x - points[i].x,
y: points[i + 1].y - points[i].y
});
}
let points2: Array<any> = new Array<any>();
for (let j: number = 0; j < dirs.length; j++) {
points2.push({
x: points[j].x + dirs[j].x * t,
y: points[j].y + dirs[j].y * t
});
}
return this.getKeyPoint(points2, t);
} else {
return { x: points[0].x, y: points[0].y };
}
}
}
04-26
441
04-08
539
04-03
356