当前位置:网站首页>Piecewise Bezier curve
Piecewise Bezier curve
2022-06-12 06:07:00 【Rulelur】
The degree of Bessel curve is too high , There may be a problem that computing performance and control points have little impact
Piecewise Bessel curve can solve this problem , Just solve the smoothing problem at the segment
Let's just draw a conclusion : When the control points on both sides and the section junction point Collinear and The line segment formed Equal length when , Satisfy the smoothness of curve
Intermediate point p1.xy = (p0.xy + p2.xy) / 2

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.translate(10, 10); // Remap... On canvas (0,0) Location , Avoid spillovers
function drawCircle(x, y, color, r = 6) {
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(x, y, r, 0, 2 * Math.PI);
ctx.fill();
}
function drawPath(path) {
ctx.beginPath();
path.forEach((p, i) => {
if (i) {
ctx.lineTo(p.x, p.y);
} else {
ctx.moveTo(p.x, p.y);
}
});
ctx.stroke();
}
function bezier(pointList, t) {
if (pointList.length === 1) {
return pointList[0];
} else {
// B(t)=(1-t)Bp0p1…pn-1(t) + tBp1p2…pn(t)
var p1 = bezier(pointList.slice(0, -1), t);
var p2 = bezier(pointList.slice(1), t);
var p = {
x: (1 - t) * p1.x + t * p2.x,
y: (1 - t) * p1.y + t * p2.y,
};
return p;
}
}
// The first curve
var startPoint = { x: 0, y: 0 };
var endPoint = { x: 500, y: 300 };
var pointList = [
startPoint,
// In the middle is the control point
{ x: 50, y: 200 },
{ x: 450, y: 200 },
endPoint,
];
draw(pointList, "green");
// The second curve
var startPoint2 = endPoint;
var endPoint2 = { x: 700, y: 100 };
var pointList2 = [
startPoint2,
// In the middle is the control point
{
x: startPoint2.x * 2 - pointList[2].x,
y: startPoint2.y * 2 - pointList[2].y,
},
{ x: 800, y: 200 },
endPoint2,
];
draw(pointList2, "black");
function draw(pointList, color) {
// draw a curve
ctx.strokeStyle = color;
var path = [];
for (var i = 0; i <= 100; i++) {
path.push(bezier(pointList, i / 100));
}
drawPath(path);
var startPoint = pointList[0];
var endPoint = pointList[pointList.length - 1];
// Red start and end points
[startPoint, endPoint].forEach((p) => {
drawCircle(p.x, p.y, "red");
});
// Blue control point
pointList.slice(1, -1).forEach((p) => {
drawCircle(p.x, p.y, color);
});
}
边栏推荐
- Database Experiment 2: data update
- Leetcode-1706. Where does the club fall
- Data integration framework seatunnel learning notes
- 获取图片的尺寸
- 数据库为什么不使用hash表?
- Es6-es11 learning
- Leetcode-93. Restore IP address
- Understand Houdini's (heightfield) remap operation
- Une explication du 80e match bihebdomadaire de leetcode
- In unity3d, billboard effect can be realized towards another target
猜你喜欢
随机推荐
夜神模拟器adb查看log
Cross compile libev
前台展示LED数字(计算器上数字类型)
Login authentication filter
摄像头拍摄运动物体,产生运动模糊/拖影的原因分析
(UE4 4.27) UE4 adds a customized meshpass to realize the edge illumination of the mobile terminal
Pytorch implementation of regression model
sqlite交叉编译动态库
R语言大作业(四):上海市、东京 1997-2018 年GDP值分析
nRF52832自定义服务与特性
Leetcode sword finger offer II 033 Modified phrase
468. verifying the IP address
2D human pose estimation for pose estimation - pifpaf:composite fields for human pose estimation
Types, functions and applications of intelligent sensors
Leetcode buckle -10 Regular expression matching analysis [recursion and dynamic programming]
Houdini & UE4 programmed generation of mountains and multi vegetation scattering points
Es6-es11 learning
nRF52832自定義服務與特性
How do I get the date and time from the Internet- How to get DateTime from the internet?
RMB classification II








