Smooth Uibezierpath

Smooth UIBezierPath

Interpolation using quadratic curve is like below:

    func
MidPoint( _ l: CGPoint, _ r: CGPoint ) -> CGPoint { return CGPoint( x: ( l.x + r.x ) / 2, y: ( l.y + r.y ) / 2 ) }
var start = CGPoint( x: 0, y: 0 )
var prev = CGPoint( x: 0, y: 0 )
for (index, ratio) in ratios.enumerated() {
let point = CGPoint(x: origin.x + cos(CGFloat(index) * incrementAngle) * radius * ratio,
y: origin.y + sin(CGFloat(index) * incrementAngle) * radius * ratio)
switch index {
case 0:
start = point
case 1:
bezier.move( to: MidPoint( start, point ) )
prev = point
default:
bezier.addQuadCurve( to: MidPoint( prev, point ), controlPoint: prev )
prev = point
}
}
bezier.addQuadCurve( to: MidPoint( prev, start ), controlPoint: prev )

Sample Image

Smooth open UIBezierPath

I have a solution to my problem. Instead of using path.addArc(), I now use a function to get as many points as I'd like along an arc and then use path.addLine() to every one of those points. If you want more points for a smoother path, just lower the value of n.

func getCirclePoints(centerPoint: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool) -> [CGPoint] {
let n : CGFloat = clockwise ? -1 : 1
let points: [CGPoint] = stride(from: startAngle - n, through: endAngle + n, by: n).map {

let degreesToRadians = CGFloat($0) * .pi / 180

let x = centerPoint.x + radius * cos(degreesToRadians)
let y = centerPoint.y + radius * sin(degreesToRadians)

return CGPoint(x: x, y: y)
}
return points
}

How to smooth curve in UIBezierPath symmetrically

I wouldn’t recommend rendering the circular bit with beziers. They’re extremely close, but not spot on. It’s fine approximation for corner rounding of a rectangle (or any polygon), but for a true circular portion of the path you should use addArc(withCenter:radius:startAngle:endAngle:clockwise:).

You can use beziers leading into and out of the arc, if you want, but for the circular portion, use an arc. E.g. see https://stackoverflow.com/a/60862388/1271826.

UIBezierPath not drawing a smooth curve

Just use this line. it will solve your problem myPath.miterLimit=-10;.

Change the value if you need to any thing it takes float value

How to smooth the joint of lines in bezier path?

If you are drawing on the UIView then the solution of adam works. But if you are drawing on CaShapeLayer (as in my case), then you have to set the lineJoin property of your shapeLayer, not the path.
This solution is explained here.

UIBezierPath - smoothing chart of choppy/noisy data

Thank you all for your support. I was away for a while. But I found a resolution to my situation that is phenomenal. It was a class that does interpolation.

https://github.com/jnfisher/ios-curve-interpolation

All I had to do was pass my array of Points and it smooths them out!

UIBezierpath is not drawing a smooth image

Try this

let roundRect = UIBezierPath(roundedRect: CGRectInset(CGRectMake(0, 0, 156, 60), 1, 1), byRoundingCorners:.AllCorners, cornerRadii: CGSizeMake(200, 200))

EDITED

or you can also do this to do it more reusable, this in your layoutSubviews

let roundRect = UIBezierPath(roundedRect: CGRectInset(self.frame, 1, 1), byRoundingCorners:.AllCorners, cornerRadii: CGSizeMake(200, 200))

Instead of

let roundRect = UIBezierPath(roundedRect: CGRectMake(0, 0, 156, 60), byRoundingCorners:.AllCorners, cornerRadii: CGSizeMake(200, 200))

the CGRectInset function create a rect inside your original rect,

Returns a rectangle that is smaller or larger than the source
rectangle, with the same center point.

EDITED
you can put this in your init to fix the visualization issue

self.contentScaleFactor = UIScreen.mainScreen().scale //SUPPORT RETINA

I hope this help you



Related Topics



Leave a reply



Submit