我需要绘制小弯曲箭头。我可以计算出箭头的角度OK,我将使用Beziers来定义路径段。但是,我真正想做的是计算开始和结束之间不可见的弯曲路径,并且仅在开始之后和结束之前从一小段距离描绘路径。
这将在起点和终点处的任何对象之间留下合适的间隙。有什么建议?
箭头通常没有疯狂的曲线,它们具有非常平滑的曲线,靠近两端的t
值表现为纯立方体(因为Bezier函数在起始坐标处由(1-t)³支配,并且由t³控制)在结束坐标处,所以在终点附近你可以“猜测”你需要插入的“t”值,以便通过使用立方根来获得一个接近需要的坐标:
// let's say we want "10% away from the end"
desiredDistance = 0.9;
// then the guestimate for the "t" value is simply the cube root of 0.9
probablyT = Math.pow(desiredDistance, 1/3);
// and the point we want to cut at is at that "t" value
cutPoint = get(probablyT, pts);
// and we can split up the curve into two segments at that "t" value
curves = split(probablyT, pts);
// and then keep the segment we need for the arrow
arrowcurve = curves[0];
请参阅http://jsbin.com/dovodibaze/edit?js,output,了解它近似于终点附近的距离(以及这显然只能在您猜测的终点附近工作=)
使用probablyT
值,您可以分割原始曲线,绘制从该分割得到的“第一”曲线(覆盖原始t = 0到t =近端段),然后在原始端绘制箭头点。
经过大量的努力,我想我可能已经找到了可能的解决方案。假设您有Bezier曲线A-B-C-D,其中B&C是控制点,A&D是起点和终点。你想从A和D开始和结束一个间隔距离X:
看到这种方法的任何问题?