zoukankan      html  css  js  c++  java
  • 3点画圆

    解三元二次方程组

    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);
    }
  • 相关阅读:
    mongodb
    python中读取文件的read、readline、readlines方法区别
    uva 129 Krypton Factor
    hdu 4734
    hdu 5182 PM2.5
    hdu 5179 beautiful number
    hdu 5178 pairs
    hdu 5176 The Experience of Love
    hdu 5175 Misaki's Kiss again
    hdu 5174 Ferries Wheel
  • 原文地址:https://www.cnblogs.com/bandy/p/4329116.html
Copyright © 2011-2022 走看看