当前位置:网站首页>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边栏推荐
- Hyperledger Fabric 2. X custom smart contract
- Convert data frame with date column to timeseries
- ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
- JDBC | Chapter 5: closing and releasing JDBC connection resources
- Observer mode vs publish subscribe mode
- Design and practice of kubernetes cluster and application monitoring scheme
- Jenkins operation Chapter 6 mail server sending build results
- Honeypot based on MySQL load data local INFILE
- MySQL learning notes
- Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction
猜你喜欢

There are two ways for golang to develop mobile applications

Games101 Lecture 10 geometry 1 Notes

百度小程序自动提交搜索

The generation of leetcode simple questions each character is an odd number of strings

Observer mode vs publish subscribe mode

VLAN experiment

Testing grpc service with grpcui

Fresnel diffraction with rectangular aperture based on MATLAB

Easy to understand TCP four waves (multi picture explanation)

ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
随机推荐
JDBC | Chapter 6: simple use of database connection pool
Personal blog item: processing of reading number +1 after viewing article details
Teach you how to develop your own NPM package (publish to the NPM official website)
Failure: unable to log in to "taxpayer equity platform"
51 lines of code, self-made TX to MySQL software!
层次分析法
Testing grpc service with grpcui
Fault: display Storport driver out of date in component health
力扣每日一题-第30天-1281.整数的各位积和之差
Longest substring between two identical characters of leetcode simple question
Design of leetcode simple problem goal parser
Games101 Lecture 10 geometry 1 Notes
Mongodb paging method
The most complete machine learning model training process
JIRA basic usage sharing
What are the uses of final?
Establishing the development environment of esp8266
Aging design guide for applets
Rich material libraries make modeling easy and efficient for developers
Servlet version conflict causes page 404