简体   繁体   English

如何在 paper.js 中为平坦曲线添加句柄

[英]How can I add handles to a flat curve in paper.js

I am trying to add handles (handleIn, handleOut) to the segments created in Paper.js using a mousetool like the following:我正在尝试使用如下所示的鼠标工具向 Paper.js 中创建的段添加句柄(handleIn、handleOut):

var myPath = new Path();
myPath.strokeColor = 'black';

function onMouseDown(event) {
    myPath.add(event.point);
}

At the end of drawing, I close the polygon, and that is when I would like the handles to be generated.在绘图结束时,我关闭多边形,这就是我想要生成手柄的时候。 Ideally there is a function or settings that would add the missing handles, but if not, any help pointing me in the right direction for how to calculate the handle positions would be greatly appreciated.理想情况下,有一个功能或设置可以添加缺少的手柄,但如果没有,任何帮助我指出如何计算手柄位置的正确方向将不胜感激。 I don't want to use smooth() or simplify() since I want the original shape of the polygon to remain.我不想使用平滑()或简化(),因为我希望保留多边形的原始形状。 I just want to have handles so that I can add subtle curves to specific line segments if necessary.我只想拥有句柄,以便在必要时可以向特定的线段添加微妙的曲线。

Handles can be set using segment.handleIn and segments.handleOut properties.可以使用segment.handleIn 和segments.handleOut 属性设置句柄。 Handles are stored relative to the segment point, you just have to make sure they are of the length you want.句柄是相对于线段点存储的,您只需要确保它们的长度是您想要的。 You can then modify them like any other vector/point.然后您可以像修改任何其他矢量/点一样修改它们。 simple demo 简单的演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM