2
我想根據控制點列表繪製曲線。 這是我所期待的: 如何根據3點以上的控制點列表繪製曲線
這裏是控制點: (0,90) (1100) (-3,145) (10150) (23155) (73108) (80,120) (86131) (40210) (50220) (60230) (148185) (140180) (131175) (23188) (0190)
這裏是我的代碼:
public List<PointType> controlPoints;
public void render(Canvas canvas, Paint paint) {
int size = controlPoints.size();
if (size < 2) {
return;
}
paint.setColor(this.color);
paint.setStyle(this.style);
Path curvePath = new Path();
PointType firstPoint = null;
PointType beginPoint = null;
for (PointType point : controlPoints) {
if (firstPoint == null) {
firstPoint = point;
} else if (beginPoint == null) {
beginPoint = point;
} else {
curvePath.moveTo(firstPoint.x, firstPoint.y);
curvePath.quadTo(beginPoint.x, beginPoint.y, point.x, point.y);
firstPoint = beginPoint;
beginPoint = point;
}
}
canvas.drawPath(curvePath, paint);
}
但結果是這樣的:
什麼是錯的,我怎麼能得出正確的曲線?
看到http://stackoverflow.com/a/3813349/794088 – petey
你需要平滑的曲線出來,用線總是會接近它類似的東西。看看貝塞爾樣條作爲第一次嘗試 –
https://github.com/autotrace也許你可以從這個鏈接拿東西..看起來你需要更多的點,因爲它畫直線... – Setar