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);
    }
  • 相关阅读:
    实现168732363.66元用逗号格式为168,732,363.66元
    程序员的十步学习法
    js中字符串方法大全
    js中数组方法大全
    异常,常用工具
    抽象类,常用类
    this 关键字
    面向对象
    DOS.JDK
    Android
  • 原文地址:https://www.cnblogs.com/bandy/p/4329116.html
Copyright © 2011-2022 走看看