24 assert(samplePoints > 1);
25 if (samplePoints <= 1)
29 result.resize(samplePoints);
30 result.front() =
first;
34 for (
unsigned k = 1; k < samplePoints - 1; ++k)
36 result[k] =
first + step * double(k);
53 return atan2(diff.
getY(), diff.
getX());
94 double line_length =
length();
97 Point2D line_unitvec = line_vec / line_length;
99 double length_of_projection =
101 return first + line_unitvec * length_of_projection;
175 const double cx = point.
getX();
176 const double cy = point.
getY();
183 const double r_numerator = (cx - ax) * (bx - ax) + (cy - ay) * (by - ay);
184 const double r_denomenator = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
185 const double r = r_numerator / r_denomenator;
190 const double s = ((ay - cy) * (bx - ax) - (ax - cx) * (by - ay) ) / r_denomenator;
192 const double distanceLine = std::abs(s) * sqrt(r_denomenator);
193 double distanceSegment = -1.0;
200 if ( (r >= 0) && (r <= 1) )
202 distanceSegment = distanceLine;
206 double dist1 = (cx - ax) * (cx - ax) + (cy - ay) * (cy - ay);
207 double dist2 = (cx - bx) * (cx - bx) + (cy - by) * (cy - by);
212 distanceSegment = sqrt(dist1);
218 distanceSegment = sqrt(dist2);
222 return distanceSegment;
227 #define SAME_SIGNS(a, b) ((a) * (b) >= 0) 228 template<
typename FloatT>
230 FloatT x3, FloatT y3, FloatT x4, FloatT y4)
232 FloatT a1, a2, b1, b2, c1, c2;
233 FloatT r1, r2, r3, r4;
237 c1 = x2 * y1 - x1 * y2;
239 r3 = a1 * x3 + b1 * y3 + c1;
240 r4 = a1 * x4 + b1 * y4 + c1;
242 if ( r3 != 0 && r4 != 0 &&
SAME_SIGNS( r3, r4 ))
247 c2 = x4 * y3 - x3 * y4;
249 r1 = a2 * x1 + b2 * y1 + c2;
250 r2 = a2 * x2 + b2 * y2 + c2;
252 if ( r1 != 0 && r2 != 0 &&
SAME_SIGNS( r1, r2 ))
263 bool has_inside_intersection =
275 if (is_vertical && other_is_vertical)
277 else if (is_vertical)
280 double oa = otherdiff.
getY() / otherdiff.
getX();
284 else if (other_is_vertical)
287 double a = diff.
getY() / diff.
getX();
294 double oa = otherdiff.
getY() / otherdiff.
getX();
296 double ta = diff.
getY() / diff.
getX();
305 *point = intersectPoint;
311 if (points.size() >= 2)
319 double minX = points.front().getX();
322 for (Polygon2D::const_iterator point = points.begin(); point != points.end(); ++point)
324 minX = std::min(minX,
double(point->getX()));
325 maxX = std::max(maxX,
double(point->getX()));
326 SSxy += (point->getX() - mean.getX()) * (point->getY() - mean.getY());
327 SSxx += (point->getX() - mean.getX()) * (point->getX() - mean.getX());
330 const double b(SSxy / SSxx);
331 const double a(mean.getY() - b * mean.getX());
static bool line2d_intersect(FloatT x1, FloatT y1, FloatT x2, FloatT y2, FloatT x3, FloatT y3, FloatT x4, FloatT y4)
std::string toString(UINT16 digits=2) const
Text output for debugging.
double dot_product(const Point2D &p1, const Point2D &p2)
IntersectingType
Describes how two lines can be intersecting.
Point2D getCenterOfGravity() const
Returns the center of gravity of this polygon.
const Point2D & getP1() const
Returns the first point.
Line2D()
Empty constructor.
double distanceToPoint(const Point2D &point) const
Returns the distance of the given point to its orthogonal projection onto this line.
Point2D second
The second point of this line.
bool containsPoint(const Point2D &point) const
Returns true if this line "contains" the given point.
Point2D getDiff() const
Returns the difference between line end and line start as a Point2D.
void setXY(value_type x, value_type y)
The lines are not intersecting, i.e. they are parallel or zero.
Polygon2D toPolygon2D() const
Conversion to Polygon2D.
Point2D projectOntoLine(const Point2D &point) const
A line in the two-dimensional plane, composed out of two points.
Point2D first
The first point of this line.
static Line2D fromLinearRegression(const Polygon2D &points)
Returns a Line2D from several points using linear regression.
double distanceFromLineSegment(const Point2D &point) const
Returns the distance of a point to this line segment.
bool isZero() const
Returns true if both points are zero.
The lines are intersecting, but outside of their line segments.
IntersectingType isIntersecting(const Line2D &other, Point2D *intersectingPoint=NULL) const
Calculates the intersection point between two lines.
The lines are intersecting within their line segments.
Point2D getCenterPoint() const
Returns the point in the middle between first and second point.
Line2D getUnitVector() const
Returns a unit vector for this line.
const Point2D & getP2() const
Returns the second point.
double getInclination() const