相关疑难解决方法(0)

绘制平滑曲线 - 需要的方法

在移动的过程中,如何在iOS绘图应用程序中平滑一组点?我尝试过UIBezier路径,但是当我只移动1,2,3,4 - 2,3,4,5点时,我得到的是它们相交的锯齿状末端.我听说过样条曲线和所有其他类型.我对iPhone编程很新,不懂如何在我的石英绘图应用程序中编程.一个坚实的例子将非常感激,我花了几个星期的圈子运行,我似乎永远不会找到任何iOS代码来完成这项任务.大多数帖子只链接到维基百科上的java模拟或页面关于曲线拟合,这对我没有任何作用.另外我不想切换到openGL ES.我希望有人能够最终提供代码来回答这个流传的问题.


这是我在UIBezierPath的代码,它在交叉点处留下了边缘///

更新到下面的答案

#define VALUE(_INDEX_) [NSValue valueWithCGPoint:points[_INDEX_]]
#define POINT(_INDEX_) [(NSValue *)[points objectAtIndex:_INDEX_] CGPointValue]

- (UIBezierPath*)smoothedPathWithGranularity:(NSInteger)granularity
{
    NSMutableArray *points = [(NSMutableArray*)[self pointsOrdered] mutableCopy];

    if (points.count < 4) return [self bezierPath];

    // Add control points to make the math make sense
    [points insertObject:[points objectAtIndex:0] atIndex:0];
    [points addObject:[points lastObject]];

    UIBezierPath *smoothedPath = [self bezierPath];
    [smoothedPath removeAllPoints];

    [smoothedPath moveToPoint:POINT(0)];

    for (NSUInteger index = 1; index < points.count - 2; index++)
    {
        CGPoint p0 = POINT(index - 1);
        CGPoint p1 = POINT(index); …
Run Code Online (Sandbox Code Playgroud)

iphone bezier objective-c ipad ios

55
推荐指数
5
解决办法
3万
查看次数

标签 统计

bezier ×1

ios ×1

ipad ×1

iphone ×1

objective-c ×1