Android 贝塞尔曲线(一)弹性圆

之前看了一篇三次贝塞尔曲线练习之弹性的圆(http://www.jianshu.com/p/791d3a791ec2#),感觉写的挺好,效果实现的不错,知道原理后,没有细看代码,自己还是先写一个版本,再比较吧。关于怎样用三次贝塞尔曲线画圆,请参考以上链接。

效果图

初步实现的效果如下:

bezier

比较关键的地方就是状态分解及实现。状态分解上面的文章讲的很清楚了,都差不多:

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

不同

不同的地方就是中间状态的时候y轴半径缩减了一些,后半程与前半程也不是对称关系。贴段后半程的部分代码:

float MValue = M * radius * (1 + ((STATE3 - fraction) / (STATE3 - STATE2)) * 0.3f);
float deltaX = unitDistance * (fraction - STATE2) / (STATE3 - STATE2);
float radius_tem = unitDistance * (STATE3 - fraction) / (STATE3 - STATE2) / 6;//y轴拉伸
mPath.moveTo(startPoint.x + (deltaX + unitDistance) * 3 / 2, startPoint.y + radius - radius_tem);

mPath.cubicTo(startPoint.x + (deltaX + unitDistance) * 3 / 2 - MValue, startPoint.y + radius - radius_tem,startPoint.x - radius + deltaX * 2 + unitDistance, startPoint.y + MValue,startPoint.x + deltaX * 2 - radius + unitDistance, startPoint.y);//第三象限

mPath.cubicTo(startPoint.x + deltaX * 2 - radius + unitDistance, startPoint.y - MValue,
startPoint.x + (deltaX + unitDistance) * 3 / 2 - MValue, startPoint.y - radius + radius_tem,startPoint.x + (deltaX + unitDistance) * 3 / 2, startPoint.y - radius + radius_tem);//第二象限

mPath.cubicTo(startPoint.x + (deltaX + unitDistance) * 3 / 2 + MValue, startPoint.y - radius + radius_tem,startPoint.x + 2 * radius + deltaX + unitDistance, startPoint.y - MValue,startPoint.x + 2 * radius + deltaX + unitDistance, startPoint.y);//第一象限

mPath.cubicTo(startPoint.x + 2 * radius + deltaX + unitDistance, startPoint.y + MValue,
startPoint.x + MValue + (deltaX + unitDistance) * 3 / 2, startPoint.y + radius radius_tem,startPoint.x + (deltaX + unitDistance) * 3 / 2, startPoint.y + radius - radius_tem);//第四象限

canvas.drawPath(mPath, mPaint);

比较乱 ,也没优化,有时间再说吧。项目代码在 https://github.com/GoldbergM/BezierDemo.

参考:http://www.jianshu.com/p/791d3a791ec2#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值