本文整理汇总了C++中Point2D::SquaredEuclideanDistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2D::SquaredEuclideanDistanceTo方法的具体用法?C++ Point2D::SquaredEuclideanDistanceTo怎么用?C++ Point2D::SquaredEuclideanDistanceTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2D
的用法示例。
在下文中一共展示了Point2D::SquaredEuclideanDistanceTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
mitk::Point2D mitk::PlanarCross::InternalApplyControlPointConstraints(unsigned int index, const Point2D &point)
{
// Apply constraints depending on current interaction state
switch (index)
{
case 2:
{
// Check if 3rd control point is outside of the range (2D area) defined by the first
// line (via the first two control points); if it is outside, clip it to the bounds
const Point2D p1 = this->GetControlPoint(0);
const Point2D p2 = this->GetControlPoint(1);
Vector2D n1 = p2 - p1;
n1.Normalize();
const Vector2D v1 = point - p1;
const double dotProduct = n1 * v1;
const Point2D crossPoint = p1 + n1 * dotProduct;
;
const Vector2D crossVector = point - crossPoint;
if (dotProduct < 0.0)
{
// Out-of-bounds on the left: clip point to left boundary
return (p1 + crossVector);
}
else if (dotProduct > p2.EuclideanDistanceTo(p1))
{
// Out-of-bounds on the right: clip point to right boundary
return (p2 + crossVector);
}
else
{
// Pass back original point
return point;
}
}
case 3:
{
// Constrain 4th control point so that with the 3rd control point it forms
// a line orthogonal to the first line (constraint 1); the 4th control point
// must lie on the opposite side of the line defined by the first two control
// points than the 3rd control point (constraint 2)
const Point2D p1 = this->GetControlPoint(0);
const Point2D p2 = this->GetControlPoint(1);
const Point2D p3 = this->GetControlPoint(2);
// Calculate distance of original point from orthogonal line the corrected
// point should lie on to project the point onto this line
Vector2D n1 = p2 - p1;
n1.Normalize();
const Vector2D v1 = point - p3;
const double dotProduct1 = n1 * v1;
const Point2D pointOnLine = point - n1 * dotProduct1;
// Project new point onto line [p1, p2]
const Vector2D v2 = pointOnLine - p1;
double dotProduct2 = n1 * v2;
const Point2D crossingPoint = p1 + n1 * dotProduct2;
// Determine whether the projected point on the line, or the crossing point should be
// used (according to the second constraint in the comment above)
if ((pointOnLine.SquaredEuclideanDistanceTo(p3) > crossingPoint.SquaredEuclideanDistanceTo(p3)) &&
(pointOnLine.SquaredEuclideanDistanceTo(p3) > pointOnLine.SquaredEuclideanDistanceTo(crossingPoint)))
{
return pointOnLine;
}
else
{
return crossingPoint;
}
}
default:
return point;
}
}