首页 文章

如何在用户触摸点之间绘制平滑曲线?

提问于
浏览
0

我正在开发一款游戏 . 用户通过手指在屏幕上绘制曲线,然后我获得用户触摸点 .

我想在这些点之间画一条曲线 . 它们分散,当我使用画布并在它们之间画线时,结果不是平滑的曲线 .

我正在寻找一些方法来绘制通过这些点的平滑曲线(可能通过修改或删除一些与其他点不同的趋势点) .

谁能帮我?

在这里我添加picture以显示我的意思

1 回答

  • 0

    正如我从Adobe Photoshop和Illustrator中了解到的那样,添加的点数越多,图像的锯齿越多 . 绘图时,您可以跳过其他所有点 . 如果用户快速移动,这可能会提供不准确的图纸,因此您可以检查跳过的点是近还是远 .

    final int len = pointsX.length, far = 50;
    for (int i = 0; i < len; i++)
    {
        if (i % 2 == 0)  //If even, draw
        {
            //Draw code
        }
        else if (Math.abs(pointsX[i] - pointsX[i-1]) > far || Math.abs(pointsY[i] - pointsY[i-1]) > far)
        {   //If the index is odd, check if the distance from the current to the last point is far.
            //If it is far, draw. If not far, skip the draw, so it doesn't appear as jagged.
            //Draw code
        }
    }
    

相关问题