本文整理汇总了C++中Point::CalcDist方法的典型用法代码示例。如果您正苦于以下问题:C++ Point::CalcDist方法的具体用法?C++ Point::CalcDist怎么用?C++ Point::CalcDist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point::CalcDist方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: circle
Circle(const Point& P1, const Point& P2, const Point& P3) {
double d1 = P1.CalcDist(P2);
double d2 = P1.CalcDist(P3);
double d3 = P2.CalcDist(P3);
if (fabs(d1+d2-d3) <= EPS) {
Circle circle(P2, P3);
center = circle.center;
radius = circle.radius;
} else if (fabs(d1+d3-d2) <= EPS) {
Circle circle(P1, P3);
center = circle.center;
radius = circle.radius;
} else if (fabs(d2+d3-d1) <= EPS) {
Circle circle(P1, P2);
center = circle.center;
radius = circle.radius;
} else {
Point M1 = Point((P1.x + P2.x) / 2, (P1.y + P2.y) / 2);
Point V = P2-P1;
Point D1 = Point(-V.y, V.x);
Point W = P3-P1;
Point M2 = Point((P1.x + P3.x) / 2, (P1.y + P3.y) / 2);
Point D2 = Point(-W.y, W.x);
assert(fabs(D1.x*D2.y - D1.y*D2.x) > EPS);
double alpha = (D2.y*(M2.x-M1.x) - D2.x*(M2.y-M1.y)) / (D1.x*D2.y - D1.y*D2.x);
center = Point(M1.x + alpha*D1.x, M1.y + alpha*D1.y);
radius = center.CalcDist(P1);
assert(fabs(radius - center.CalcDist(P2)) < EPS);
assert(fabs(radius - center.CalcDist(P3)) < EPS);
}
}
示例2: Contains
int Contains(const Point& P) const {
return center.CalcDist(P) <= radius + EPS;
}
示例3: Circle
Circle(const Point& P1, const Point& P2) {
center = Point((P1.x + P2.x) / 2, (P1.y + P2.y) / 2);
radius = center.CalcDist(P2);
}