Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The key to getting two bezier curves to join smoothly is that the relevant control points and the start/end points on the curves must be collinear. Think of the control point and the endpoint as forming a line that's tangent to the curve at the endpoint. If one curve starts at the same point where another ends, and if they both have the same tangent line at that point, the curve will be smooth. Here's a bit of code to illustrate:</p> <pre><code>- (void)drawRect:(CGRect)rect { #define commonY 117 CGPoint point1 = CGPointMake(20, 20); CGPoint point2 = CGPointMake(100, commonY); CGPoint point3 = CGPointMake(200, 50); CGPoint controlPoint1 = CGPointMake(50, 60); CGPoint controlPoint2 = CGPointMake(20, commonY); CGPoint controlPoint3 = CGPointMake(200, commonY); CGPoint controlPoint4 = CGPointMake(250, 75); UIBezierPath *path1 = [UIBezierPath bezierPath]; UIBezierPath *path2 = [UIBezierPath bezierPath]; [path1 setLineWidth:3.0]; [path1 moveToPoint:point1]; [path1 addCurveToPoint:point2 controlPoint1:controlPoint1 controlPoint2:controlPoint2]; [[UIColor blueColor] set]; [path1 stroke]; [path2 setLineWidth:3.0]; [path2 moveToPoint:point2]; [path2 addCurveToPoint:point3 controlPoint1:controlPoint3 controlPoint2:controlPoint4]; [[UIColor orangeColor] set]; [path2 stroke]; } </code></pre> <p>Notice that <code>path1</code> ends at <code>point2</code>, <code>path2</code> starts at <code>point2</code>, and control points 2 and 3 share the same Y-value, <code>commonY</code>, with <code>point2</code>. You can change any of the values in the code as you like; as long as those three points all fall on the same line, the two paths will join smoothly. (In the code above, the line is <code>y = commonY</code>. The line doesn't have to be parallel to the X axis; it's just easier to see that the points are collinear that way.)</p> <p>Here's the image that the code above draws:</p> <p><img src="https://i.stack.imgur.com/PPTbv.png" alt="two paths joined smoothly"></p> <p>After looking at your code, the reason that your curve is jagged is that you're thinking of control points as points on the curve. In a bezier curve, the control points are usually not on the curve. Since you're taking the control points from the curve, the control points and the point of intersection are <em>not</em> collinear, and the paths therefore don't join smoothly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload