zoukankan      html  css  js  c++  java
  • 园与直线相交

    center (a,b)

    (1)(x-a)^2 + (y-b)^2  =  R^2

    (2)直线  y = kx +b; 

    (2)带入(1)得到2元1次多项式

    ax^2 + bx + c = 0;

    求dlt = b^2 - 4ac;

    x = -b/2a +- sqrtl(dlt)

    代入(2) 求y

     static Pointf _CalculateCenter(Point p1, Point p2, Point p3)
    {
        Pointf ptCenter = {0.0};
        // P1 -- P2 -- P3
        //P1P2
        float k1 = float(p2.y - p1.y) / float(p2.x - p1.x);

        // center point of P1P2
        float cx1 = ((float)p1.x + (float)p2.x) / 2;
        float cy1 = ((float)p1.y + (float)p2.y) / 2;

        //P1P2 perpendicular bisector
        float ck1 = -1 / k1;
        float cb1 = cy1 - ck1 * cx1;

        //P2P3
        float k2 = float(p3.y - p2.y) / float(p3.x - p2.x);

        // center point of P1P2
        float cx2 = ((float)p2.x + (float)p3.x) / 2;
        float cy2 = ((float)p2.y + (float)p3.y) / 2;

        //P2P3 perpendicular bisector
        float ck2 = -1 / k2;
        float cb2 = cy2 - ck2 * cx2;

        ptCenter.x = (cb1 - cb2) / (ck2 - ck1);
        ptCenter.y = ck1 * (cb1 - cb2) / (ck2 - ck1) + cb1;

        return ptCenter;
    }

  • 相关阅读:
    软考之操作系统
    牛腩javascript(二)之正则表达式
    牛腩javascript(一)
    软考之算法
    软考之数据结构
    软考之路之刷屏开始
    XML中的几种比较
    北大青鸟ASP.NET之总结篇
    Webassembly 学习2 -- Js 与C 数据交互
    nginx-proxy_redirect
  • 原文地址:https://www.cnblogs.com/zhoug2020/p/5794304.html
Copyright © 2011-2022 走看看