标签:
最近在研究一个问题,有一系列点,需要拟合成一条漂亮的曲线,绘制出来,研究结果如下,感谢网友!
// 获取一系列点的曲线路径 private Path getPointCurvePath(List<Point> points) { Point startp; Point endp; Point p3 = new Point(); Point p4 = new Point(); Path path = new Path(); if (null == points || 0 == points.size()) { return path; } startp = points.get(0); path.moveTo(startp.x, startp.y); int xCenter, yCenter; for (int i = 0; i < points.size() - 1; i++) { startp = points.get(i); endp = points.get(i+1); xCenter = (int)(startp.getX() + endp.getX()) / 2; yCenter = (int)(startp.getY() + endp.getY()) / 2; p3.y = startp.y; p3.x = xCenter; p4.y = endp.y; p4.x = xCenter; // 确定曲线的路径 path.cubicTo(p3.x, p3.y, p4.x, p4.y, endp.x, endp.y); // path.quadTo(xCenter, yCenter, endp.x, endp.y); } return path; }
效果如下:
标签:
原文地址:http://blog.csdn.net/haart/article/details/43083063