相关疑难解决方法(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万
查看次数

如何在UIView中绘制Bezier曲线

我需要在a中创建一条曲线,UIView如下图所示.我必须使用UIBezierPath.请帮我解决这个问题.

我也想知道如何从水平轴上翻转曲线,这样我的弧顶部和底部底部.

贝塞尔路径的示例

core-graphics objective-c ios uibezierpath

3
推荐指数
1
解决办法
3017
查看次数

如何在iOS中绘制平滑曲线的折线图?

我有一些像 (x1,y1), (x2,y2), (x3,y3)...

现在我想绘制一个曲线平滑的图表?

我正在尝试绘制如下

-(void)drawPrices
{
    NSInteger count = self.prices.count;
    
    UIBezierPath *path = [UIBezierPath bezierPath]; 
    path.lineCapStyle = kCGLineCapRound;

    for(int i=0; i<count-1; i++)
    {
        CGPoint controlPoint[2];
        
        CGPoint p = [self pointWithIndex:i inData:self.prices];
        if(i==0)
        {
            [path moveToPoint:p];
        }

        CGPoint nextPoint, previousPoint, m;
        nextPoint = [self pointWithIndex:i+1 inData:self.prices];
        previousPoint = [self pointWithIndex:i-1 inData:self.prices];
        
        if(i > 0) {
            m.x = (nextPoint.x - previousPoint.x) / 2;
            m.y = (nextPoint.y - previousPoint.y) / 2;
        } else {
            m.x = (nextPoint.x - p.x) / 2; …
Run Code Online (Sandbox Code Playgroud)

charts curve ios

1
推荐指数
1
解决办法
2750
查看次数

标签 统计

ios ×3

objective-c ×2

bezier ×1

charts ×1

core-graphics ×1

curve ×1

ipad ×1

iphone ×1

uibezierpath ×1