// uva12304 2d geometry 110 in 1!
// rujia liu
#include#include#include#include#include#include#includeusing namespace std;
const double eps = 1e-6;
int dcmp(double x)
const double pi = acos(-1);
struct point
};typedef point vector;
vector operator + (vector a, vector b)
vector operator - (point a, point b)
vector operator * (vector a, double p)
vector operator / (vector a, double p)
bool operator < (const point& a, const point& b)
bool operator == (const point& a, const point &b)
double dot(vector a, vector b)
double length(vector a)
double angle(vector a, vector b)
double cross(vector a, vector b)
vector rotate(vector a, double rad)
vector normal(vector a)
point getlineintersection(point p, point v, point q, point w)
point getlineprojection(point p, point a, point b)
double distancetoline(point p, point a, point b)
struct line
point point(double t)
line move(double d)
};struct circle
point point(double a)
};point getlineintersection(line a, line b)
double angle(vector v)
int getlinecircleintersection(line l, circle c, double& t1, double& t2, vector& sol)
// 相交
t1 = (-f - sqrt(delta)) / (2 * e); sol.push_back(l.point(t1));
t2 = (-f + sqrt(delta)) / (2 * e); sol.push_back(l.point(t2));
return 2;
}int getcirclecircleintersection(circle c1, circle c2, vector& sol)
if(dcmp(c1.r + c2.r - d) < 0) return 0;
if(dcmp(fabs(c1.r-c2.r) - d) > 0) return 0;
double a = angle(c2.c - c1.c);
double da = acos((c1.r*c1.r + d*d - c2.r*c2.r) / (2*c1.r*d));
point p1 = c1.point(a-da), p2 = c1.point(a+da);
sol.push_back(p1);
if(p1 == p2) return 1;
sol.push_back(p2);
return 2;
}/******************* problem 1 **********************/
circle circumscribedcircle(point p1, point p2, point p3)
/******************* problem 2 **********************/
circle inscribedcircle(point p1, point p2, point p3)
/******************* problem 3 **********************/
// 過點p到圓c的切線。v[i]是第i條切線的向量。返回切線條數
int gettangents(point p, circle c, vector* v) else
}/******************* problem 4 **********************/
vectorcirclethroughpointtangenttolinegivenradius(point p, line l, double r)
/******************* problem 5 **********************/
vectorcircletangenttolinesgivenradius(line a, line b, double r)
/******************* problem 6 **********************/
vectorcircletangenttotwodisjointcircleswithradius(circle c1, circle c2, double r)
// formatting
double lineangledegree(vector v)
void format(circle c)
void format(const vector& ans)
printf("]\n");
}void format(const vector& ans)
printf("]\n");
}line getline(double x1, double y1, double x2, double y2)
int main()
if(cmd == "inscribedcircle")
if(cmd == "tangentlinethroughpoint")
if(cmd == "circlethroughapointandtangenttoalinewithradius")
if(cmd == "circletangenttotwolineswithradius")
if(cmd == "circletangenttotwodisjointcircleswithradius")
} return 0;
}
劉汝佳的**,看了這麼多模板,還是最可靠的;
要熟練運用定比分點,直接算距離誤差大。
uva 11178 計算幾何
函式較多,作為模板。include include include using namespace std struct point 定義點的時候直接利用建構函式,很方便 typedef point vector 這裡因為向量都有兩個維度的有序參量 vector operator vector a,...
UVA 11178 計算幾何
題目大意 求乙個三角形中每個內角的角三等分線組成的三角形的三個點的座標 題目解析 沒有演算法可言,直接上模板 ac includeusing namespace std struct point typedef point vector vector operator vector a,vector...
Modiz 《幾何模板》
include include include include include include define eps 1e 9 include define pi acos 1 using namespace std const double pi acos 1.0 int dcmp double ...