对于具有通常的四个点a,b,c和d的三次Bézier曲线,
对于给定值t,
如何最优雅地找到那一点的切线?
我想绘制任何(随机)曲线,给定:
我怎么能做这样的东西限制画布边界,加上曲线不能交叉.我试图找到一些解决方案,但我无法弄明白.谢谢你的时间.
以下是我想要完成的更详细的视图:
这是在画布上绘制的二次曲线.一切都好.问题是,如何在没有所有点的情况下绘制这个,只需要以像素为单位的固定长度,随机点,以画布大小和非交叉为界.

代码看起来像这样:
function fixedCurve( A, B, length ){
for(int i = A; i < B; i++){
//Calculate random point with propper distance to get first base point, random direction could be calculated before loop.
//Basicly this loop should calculate integrate of the curve and draw it each step.
}
}
Run Code Online (Sandbox Code Playgroud) 我喜欢从贝塞尔曲线中得到一些点。我发现
位置很容易。首先,计算混合函数。这些控制您的控制点在曲线上的“效果”。
B0_t = (1-t)^3
B1_t = 3 * t * (1-t)^2
B2_t = 3 * t^2 * (1-t)
B3_t = t^3
Run Code Online (Sandbox Code Playgroud)
请注意当 t 为 0 时 B0_t 是 1(并且其他所有内容都为零)。此外,当 t 为 1 时 B3_t 为 1(其他所有内容均为零)。所以曲线从 (ax, ay) 开始,到 (dx, dy) 结束。任何中间点 (px_t, py_t) 将由以下给出(将 t 从 0 变化到 1,在循环内以小增量):
px_t = (B0_t * ax) + (B1_t * bx) + (B2_t * cx) + (B3_t * dx)
py_t = (B0_t * ay) + (B1_t * by) + …Run Code Online (Sandbox Code Playgroud)