当前位置:网站首页>Draw smooth curves - methods needed - drawing smooth curves - methods needed
Draw smooth curves - methods needed - drawing smooth curves - methods needed
2022-06-29 06:35:00 【Technology feast】
problem :
How do you smooth a set of points in an iOS drawing app WHILE MOVING? How to smooth when moving iOS A set of points in a drawing application ?I have tried UIBezierpaths but all I get are jagged ends where they intersect, when I just shift the points 1,2,3,4 - 2,3,4,5. I tried UIBezierpaths But all I get is the jagged end where they intersect , When I just move a little 1,2,3,4 - 2,3,4,5 when .I have heard of spline curves and all the other types. I've heard of splines and all other types .I am quite new to iPhone programming and do not understand how to program it in my quartz drawing app. I am right. iPhone Programming is strange , I don't know how to program in my quartz drawing application .A solid example would be greatly appreciated, I have spent weeks running in circles and I can never seem to find any iOS code for this task. A reliable example would be appreciated , I spent weeks running in circles , I can never seem to find any of this task iOS Code .Most of the posts just link to a java simulation or pages on wikipedia about curve fitting which does nothing for me. Most posts just link to Java Simulation or Wikipedia page about curve fitting , It doesn't help me in any way .Also I do not want to switch to openGL ES. I don't want to switch to openGL ES.I hope someone can finally provide code to answer this circulating question. I hope someone will eventually provide code to answer this circular question .
This was my code for the UIBezierPath which left edges at intersection/// This is my UIBezierPath Code , It leaves an edge at the intersection //
UPDATED TO AN ANSWER BELOW Update to the answer below
#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); CGPoint p2 = POINT(index + 1); CGPoint p3 = POINT(index + 2); // now add n points starting at p1 + dx/dy up until p2 using Catmull-Rom splines for (int i = 1; i < granularity; i++) { float t = (float) i * (1.0f / (float) granularity); float tt = t * t; float ttt = tt * t; CGPoint pi; // intermediate point pi.x = 0.5 * (2*p1.x+(p2.x-p0.x)*t + (2*p0.x-5*p1.x+4*p2.x-p3.x)*tt + (3*p1.x-p0.x-3*p2.x+p3.x)*ttt); pi.y = 0.5 * (2*p1.y+(p2.y-p0.y)*t + (2*p0.y-5*p1.y+4*p2.y-p3.y)*tt + (3*p1.y-p0.y-3*p2.y+p3.y)*ttt); [smoothedPath addLineToPoint:pi]; } // Now add p2 [smoothedPath addLineToPoint:p2]; } // finish by adding the last point [smoothedPath addLineToPoint:POINT(points.count - 1)]; return smoothedPath;}- (PVPoint *)pointAppendingCGPoint:(CGPoint)CGPoint{ PVPoint *newPoint = [[PVPoint alloc] initInsertingIntoManagedObjectContext:[self managedObjectContext]]; [newPoint setCGPoint:CGPoint]; [newPoint setOrder:[NSNumber numberWithUnsignedInteger:[[self points] count]]]; [[self mutableSetValueForKey:@"points"] addObject:newPoint]; [(NSMutableArray *)[self pointsOrdered] addObject:newPoint]; [[self bezierPath] addLineToPoint:CGPoint]; return [newPoint autorelease]; if ([self bezierPath] && [pointsOrdered count] > 3) { PVPoint *control1 = [pointsOrdered objectAtIndex:[pointsOrdered count] - 2]; PVPoint *control2 = [pointsOrdered objectAtIndex:[pointsOrdered count] - 1]; [bezierPath moveToPoint:[[pointsOrdered objectAtIndex:[pointsOrdered count] - 3] CGPoint]]; [[self bezierPath] addCurveToPoint:CGPoint controlPoint1:[control1 CGPoint] controlPoint2:[control2 CGPoint]]; }}- (BOOL)isComplete { return [[self points] count] > 1; }- (UIBezierPath *)bezierPath{ if (!bezierPath) { bezierPath = [UIBezierPath bezierPath]; for (NSUInteger p = 0; p < [[self points] count]; p++) { if (!p) [bezierPath moveToPoint:[(PVPoint *)[[self pointsOrdered] objectAtIndex:p] CGPoint]]; else [bezierPath addLineToPoint:[(PVPoint *)[[self pointsOrdered] objectAtIndex:p] CGPoint]]; } [bezierPath retain]; } return bezierPath;}- (CGPathRef)CGPath{ return [[self bezierPath] CGPath];}
Solution :
Reference resources : https://stackoom.com/en/question/aVy4边栏推荐
- Devops development, operation and maintenance Basics: using Jenkins to automatically build projects and notify by email
- I would like to ask what securities dealers recommend? Is it safe to open an account online?
- Subtotal of C language -- basic data types and their representations
- How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)
- Clickhouse data type
- Implementation of queue
- 2022.02.14 - 239. A single element in an ordered array
- RedisTemplate处理hash整数类型的问题解析
- Fault: administrator account cannot be selected for login
- Programming specification and variables of shell script
猜你喜欢

Segment in Lucene

Agile invincible event

2022.02.15 - 240. Lucky number in matrix

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- multi axis mirroring function

Regular expressions for shell script values

There are two ways for golang to develop mobile applications

It turns out that the joys and sorrows of programmers are not interlinked
![[chromium] win10 vs2019 environment chromium configuration and compilation.](/img/20/428e6b22ed6955a732dd14d5ff0e3d.jpg)
[chromium] win10 vs2019 environment chromium configuration and compilation.

Programming specification and variables of shell script

Fault: ntfrs warning log for id13562
随机推荐
Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function
Hustoj SPJ example
Hyperledger Fabric 2. X custom smart contract
After “Go to Definition”, is there a command to return to where you came from?
Fault: display Storport driver out of date in component health
Week 12 - task 2- shoulder to shoulder cadres
Antd work item memo w3.0
2022.02.15 - SX10-31. House raiding III
Call the computer calculator and use it to convert several base numbers
Why can't the article be posted?
What are the uses of final?
Fault: KDC warning log for id29
Failure: unable to log in to "taxpayer equity platform"
Devops development, operation and maintenance Basics: using Jenkins to automatically build projects and notify by email
Monitor employee turnover dynamics. This system makes employees tremble!
Internet enterprises need CRM software to help
The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
CCTV revealed that xumengtao won the black Technology: there was a virtual coach???
2022-01 Microsoft vulnerability notification
力扣每日一题-第30天-594.最长和谐子序列