园与直线相交

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;
}

时间: 2024-08-08 05:11:11

园与直线相交的相关文章

直线与直线相交 直线与线段相交 线段与线段相交

int sgn(double x) { if(fabs(x) < eps) return 0; return x < 0 ? -1:1; } struct Point { double x,y; Point() {} Point(double _x,double _y) { x = _x,y = _y; } Point operator -(const Point &b)const { return Point(x - b.x,y - b.y); } //叉积 double opera

判断线段和直线相交 POJ 3304

1 // 判断线段和直线相交 POJ 3304 2 // 思路: 3 // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. 4 5 #include <cstdio> 6 #include <cstring> 7 #include <iostream> 8 #include <algorithm> 9 #include <map> 10 #include <set> 11 #inclu

poj2074Line of Sight(直线相交)

链接 几何细节题. 对于每一个障碍物可以求出它在地产线上的覆盖区间,如下图. 紫色部分即为每个障碍物所覆盖掉的区间,求出所有的,扫描一遍即可. 几个需要注意的地方:直线可能与地产线没有交点,可视区间可能包含地产线的端点,扫描的时候保留当前扫到的最大值. 代码中的数据很经典,供参考. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #inc

poj 1127(直线相交+并查集)

Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table and players try to remove them one-by-one without disturbing the other straws. Here, we are only concerned with if various pairs o

Jack Straws(并差集和判断直线相交问题)

Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3155   Accepted: 1418 Description In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table and players try to remove them one-by-one witho

POJ 1269 Intersecting Lines(判断直线相交)

题目地址:POJ 1269 直接套模板就可以了...实在不想自己写模板了...写的又臭又长....不过这题需要注意的是要先判断是否有直线垂直X轴的情况. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h>

UVA_11178_Morley&#39;s_Theorem_(向量旋转+直线相交)

描述 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_problem&problem=2119 Morley定理:作三角形ABC每个内角的三等分线,相交形成三角形DEF,则三角形DEF是等边三角形. 给出三角形的三个顶点ABC的坐标,求出DEF的坐标. 11178 - Morley's Theorem Time limit: 3.000 s

poj 1556 zoj1721 BellmanFord 最短路+判断直线相交

http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6120   Accepted: 2455 Description You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will a

直线相交 POJ 1269

1 // 直线相交 POJ 1269 2 3 // #include <bits/stdc++.h> 4 #include <iostream> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <algorithm> 8 #include <math.h> 9 using namespace std; 10 #define LL long long 11 typedef pair