码迷,mamicode.com
首页 > 其他好文 > 详细

3点画圆

时间:2015-03-11 10:48:33      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

解三元二次方程组

X,Y,R为未知数,x1,y1,x2,y2,x3,y3为3点坐标

(x1-X)²-(y1-Y)²=R²

(x2-X)²-(y2-Y)²=R²

(x3-X)²-(y3-Y)²=R²

 

- (void)drawRect:(CGRect)rect {
    CGPoint point1=CGPointMake(40, 40);
    CGPoint point2=CGPointMake(40, 80);
    CGPoint point3=CGPointMake(80, 100);
    float a=2*(point2.x-point1.x);
    float b=2*(point2.y-point1.y);
    float c=point2.x*point2.x+point2.y*point2.y-point1.x*point1.x-point1.y*point1.y;
    float d=2*(point3.x-point2.x);
    float e=2*(point3.y-point2.y);
    float f=point3.x*point3.x+point3.y*point3.y-point2.x*point2.x-point2.y*point2.y;
    //圆心
    float x=(b*f-e*c)/(b*d-e*a);
    float y=(d*c-a*f)/(b*d-e*a);
    //半径
    float r=sqrt((x-point1.x)*(x-point1.x)+(y-point1.y)*(y-point1.y));
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    [[UIColor redColor] set];
    CGContextAddArc(context, x, y, r, 0, 2*M_PI, 1);
    CGContextDrawPath(context, kCGPathStroke);
    [[UIColor greenColor] set];
    CGContextFillRect(context, CGRectMake(point1.x-0.5,point1.y-0.5,1,1));
    CGContextFillRect(context, CGRectMake(point2.x-0.5,point2.y-0.5,1,1));
    CGContextFillRect(context, CGRectMake(point3.x-0.5,point3.y-0.5,1,1));
    CGContextDrawPath(context, kCGPathStroke);
}

 

3点画圆

标签:

原文地址:http://www.cnblogs.com/bandy/p/4329116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!