/**
* 通过绘制Path构建一个ShapeDrawable,用来绘制到画布Canvas上
* @return
*/
private ShapeDrawable drawGooView() {
Path path = new Path();
//1. 根据当前两圆圆心的距离计算出固定圆的半径
float distance = (float) GeometryUtil.getDistanceBetween2Points(mDragCenter, mStickCenter);
stickCircleTempRadius = getCurrentRadius(distance);
//2. 计算出经过两圆圆心连线的垂线的dragLineK(对边比临边)。求出四个交点坐标
float xDiff = mStickCenter.x - mDragCenter.x;
Double dragLineK = null;
if(xDiff != 0){
dragLineK = (double) ((mStickCenter.y - mDragCenter.y) / xDiff);
}
//分别获得经过两圆圆心连线的垂线与圆的交点(两条垂线平行,所以dragLineK相等)。
PointF[] dragPoints = GeometryUtil.getIntersectionPoints(mDragCenter, dragCircleRadius, dragLineK);
PointF[] stickPoints = GeometryUtil.getIntersectionPoints(mStickCenter, stickCircleTempRadius, dragLineK);
//3. 以两圆连线的0.618处作为 贝塞尔曲线 的控制点。(选一个中间点附近的控制点)
PointF pointByPercent = GeometryUtil.getPointByPercent(mDragCenter, mStickCenter, 0.618f);
// 绘制两圆连接
//此处参见示意图{@link https://github.com/PoplarTang/DragGooView }
path.moveTo((float)stickPoints[0].x, (float)stickPoints[0].y);
path.quadTo((float)pointByPercent.x, (float)pointByPercent.y,
(float)dragPoints[0].x, (float)dragPoints[0].y);
path.lineTo((float)dragPoints[1].x, (float)dragPoints[1].y);
path.quadTo((float)pointByPercent.x, (float)pointByPercent.y,
(float)stickPoints[1].x, (float)stickPoints[1].y);
path.close();
//将四个交点画到屏幕上
// path.addCircle((float)dragPoints[0].x, (float)dragPoints[0].y, 5, Direction.CW);
// path.addCircle((float)dragPoints[1].x, (float)dragPoints[1].y, 5, Direction.CW);
// path.addCircle((float)stickPoints[0].x, (float)stickPoints[0].y, 5, Direction.CW);
// path.addCircle((float)stickPoints[1].x, (float)stickPoints[1].y, 5, Direction.CW);
//构建ShapeDrawable
ShapeDrawable shapeDrawable = new ShapeDrawable(new PathShape(path, 50f, 50f));
shapeDrawable.getPaint().setColor(Color.RED);
return shapeDrawable;
}
GooView.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:imitateQQ
作者:
评论列表
文章目录