我需要绘制小的弯曲箭头。我可以算出箭头的角度,好吧,我将使用贝塞尔曲线来定义路径段。但是,我真正想做的是计算起点和终点之间的不可见曲线路径,并且仅在起点之后和终点之前的一小段距离处描边路径。
这将在起点和终点的任何对象之间留下合适的间隙。有什么建议么?
箭头通常没有非常混乱的曲线,它们具有非常平滑的曲线,t
靠近两端的值表现为纯三次方(因为贝塞尔函数在起始坐标处由 (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,输出如何接近终点附近的距离(以及这显然仅在您猜测的终点附近有效=)
使用该probablyT
值,您可以拆分原始曲线,绘制从该拆分中获得的“第一条”曲线(覆盖原始 t=0 到 t=near-the-end 段),然后在原始端点绘制箭头.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句