javascript - 如何将arcto转换为贝塞尔曲线?

标签 javascript bezier

2 个函数(HTML5 Canvas):

  • arcTo(x1, y1, x2, y2, 半径);
  • arcTo(x1, y1, x2, y2, rx, ry, 旋转);

如何转换为贝塞尔(或二次)曲线?

谢谢。

最佳答案

谢谢=)。

var from = [200,200],
    to   = [400,300],
    tan  = [300,300], // tangent
    rad  = 50; // radius

var line = [
    from,
    computeVec(tan[0], tan[1], -tan[0]*2, -tan[1]*2, rad)
];

var quad = [
    tan,
    computeVec(tan[0], tan[1], to[0], to[1], rad)
];

ctx.moveTo(line[0][0], line[0][1]);
ctx.lineTo(line[1][0], line[1][1]);
ctx.bezierCurveTo(quad[0][0], quad[0][1], quad[0][0], quad[0][1], quad[1][0], quad[1][1]);

function computeVec(tanx, tany, x, y, rad){
    x -= tanx;
    y -= tany;
    var hypotenuse = Math.sqrt(x * x + y * y),
        proportion = rad / hypotenuse;
    return [
        tanx + (x * proportion),
        tany + (y * proportion)
    ];
}

关于javascript - 如何将arcto转换为贝塞尔曲线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13443112/

相关文章:

javascript - 在html元素中显示Jquery数据

javascript - 在设置了 MaxLength 的文本字段中查找粘贴文本的长度

javascript - this.state 在 React 组件中引用了什么?

javascript 'curry' ,需要对此代码进行一些解释

math - 计算三次贝塞尔曲线的拐点?

algorithm - 如何求贝塞尔曲线的平均速度和加速度?

iphone - 触摸移动时的贝塞尔曲线示例代码

javascript - jspm 强制错误的默认值

wpf - 如何在 WPF 中以编程方式绘制贝塞尔曲线?

ios - 手动绘制贝塞尔曲线