2014-04-24 1 views
1
I 세 점 A, B 및 C를 가지고

, 코드방법, 두 라인의 교차점이다

// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    NSArray *points = @[  [NSValue valueWithCGPoint:CGPointMake(10.0f, 15.0f)], 
           [NSValue valueWithCGPoint:CGPointMake(100.0f, 170.0f)], 
           [NSValue valueWithCGPoint:CGPointMake(190.0f, 100.0f)], 
           ]; 

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); 
    CGContextSetLineWidth(context, 2.0f); 
    CGContextSetLineJoin(context, kCGLineJoinRound); 
    CGContextSetLineCap(context, kCGLineCapRound); 


    for(int i = 0;i<points.count; ++i){ 

     NSValue *pointValue = [points objectAtIndex:i]; 
     CGPoint point = [pointValue CGPointValue]; 
     if (i == 0) { 
      CGContextMoveToPoint(context, point.x, point.y); 
     } else { 
      CGContextAddLineToPoint(context, point.x, point.y); 
     } 
    } 
    CGContextStrokePath(context); 
} 

enter image description here

그러나 다음과 같이 세 점을 연결하는 원 레코더와 함께 라인에 합류 각도, 둥근 구석으로 B 지점에 합류해야합니다. 다음 그림과 같이 :

enter image description here

는 그것을 어떻게 할까?

답변

2

당신이 가지고있는 것은 직선 2 개입니다. 원하는 것은 아크/베 지어 커브입니다 (2 직선이 될 수도 있음).

CGPathAddArcToPoint 또는 CGPathAddCurveToPoint 또는 CGPathAddQuadCurveToPoint을 사용합니다.

관련 문제