bool isLineSegmentIntersecting(const Polyline& ply, GEOLIB::Point const& s0, GEOLIB::Point const& s1) { const size_t n(ply.getNumberOfPoints() - 1); bool intersect(false); GEOLIB::Point intersection_pnt; for (size_t k(0); k < n && !intersect; k++) { intersect = MathLib::lineSegmentIntersect(*(ply.getPoint(k)), *(ply.getPoint(k + 1)), s0, s1, intersection_pnt); } return intersect; }
void BezierSpline::convertFromPolyline(const Polyline &polyline, int smooth_coefficient) { float scale = 1.0/smooth_coefficient; int n = polyline.numPoints(); assert(n >= 2); for (int i = 0; i < n; ++i) addControlPoint(polyline.getPoint(i)); // for (int i = 0; i < n; ++i) // { // if (i == 0) // is first // { // Eigen::Vector3f p1 = polyline.getPoint(i); // Eigen::Vector3f p2 = polyline.getPoint(i+1); // Eigen::Vector3f tangent = (p2 - p1); // Eigen::Vector3f q1 = p1 + scale * tangent; // addControlPoint(p1); // addControlPoint(q1); // } else if (i == n - 1) // { // Eigen::Vector3f p0 = polyline.getPoint(i-1); // Eigen::Vector3f p1 = polyline.getPoint(i); // Eigen::Vector3f tangent = (p1 - p0); // Eigen::Vector3f q0 = p1 - scale * tangent; // addControlPoint(q0); // addControlPoint(p1); // } else // { // Eigen::Vector3f p0 = polyline.getPoint(i-1); // Eigen::Vector3f p1 = polyline.getPoint(i); // Eigen::Vector3f p2 = polyline.getPoint(i+1); // Eigen::Vector3f tangent = (p2 - p0).normalized(); // Eigen::Vector3f q0 = p1 - scale * tangent * (p1 - p0).norm(); // Eigen::Vector3f q1 = p1 + scale * tangent * (p2 - p1).norm(); // addControlPoint(q0); // addControlPoint(p1); // addControlPoint(q1); // } // } setClosed(polyline.closed()); }
bool Polygon::isPartOfPolylineInPolygon(const Polyline& ply) const { const std::size_t ply_size (ply.getNumberOfPoints()); // check points for (std::size_t k(0); k < ply_size; k++) { if (isPntInPolygon (*(ply.getPoint(k)))) { return true; } } GeoLib::Point s; for (auto polygon_seg : *this) { for (auto polyline_seg : ply) { if (GeoLib::lineSegmentIntersect(polyline_seg, polygon_seg, s)) { return true; } } } return false; }