GithubHelp home page GithubHelp logo

Offset failure about cavaliercontours HOT 5 OPEN

timoria21 avatar timoria21 commented on May 25, 2024
Offset failure

from cavaliercontours.

Comments (5)

jbuckmccready avatar jbuckmccready commented on May 25, 2024

The circle intersections at the end points is required to form slices and discard them in cases where the end point of the open polyline wraps back on itself. The reason it chooses this approach is for the following reasons:

  1. It ensures the resulting offset is never closer to the original polyline than the offset value given.
  2. The resulting offset polyline is not self intersecting if the input polyline was not self intersecting.
  3. The "gap" generated is consistent in the case of a self intersecting polyline (e.g., imagine if you offset both directions at the same time by the same amount then it will form a proper "tube" around the input polyline even if the end point wraps back on itself).

See the following example:
image

Forming a "tube" by offsetting both directions the same amount, one direction is colored blue, the other is colored red. Note the point at which the slices join between the red and blue offset where the arrow points would not exist if the circle intersects were not applied.
image

This could definitely be an optional thing and the algorithm should still work (there isn't a "right" answer about what it should do at the end points), so if you have a different use case you could change it.

from cavaliercontours.

timoria21 avatar timoria21 commented on May 25, 2024

Thanks,

So in my situation (please, refer to the attached picture) it is safe to assume that, if this circle intersects the raw offset in its exact start/end point, this specific intersection itself could be ignored; is it correct?

image

from cavaliercontours.

jbuckmccready avatar jbuckmccready commented on May 25, 2024

Yes... The algorithm in cavalier contours should probably check for that case and disregard the intersect point as an optimization (the algorithm should still work correctly even with the intersect at the end point).

Based on your example you may have problems due to the offset distance (2e-5) being too close to the default epsilon values (pos_equal-eps = 1e-5 and slice_join_eps = 1e-4).

from cavaliercontours.

timoria21 avatar timoria21 commented on May 25, 2024

Hello again,

for the sake of completeness of this discussion, I managed these cases as follows: do you agree with the proposed change?

template <typename Real>
std::vector<OpenPolylineSlice<Real>>
dualSliceAtIntersectsForOffset(Polyline<Real> const& originalPline,
    Polyline<Real> const& rawOffsetPline,
    Polyline<Real> const& dualRawOffsetPline, Real offset) {
    std::vector<OpenPolylineSlice<Real>> result;
    if (rawOffsetPline.size() < 2) {
        return result;
    }

    StaticSpatialIndex<Real> origPlineSpatialIndex = createApproxSpatialIndex(originalPline);
    StaticSpatialIndex<Real> rawOffsetPlineSpatialIndex = createApproxSpatialIndex(rawOffsetPline);

    std::vector<PlineIntersect<Real>> selfIntersects;
    allSelfIntersects(rawOffsetPline, selfIntersects, rawOffsetPlineSpatialIndex);

    PlineIntersectsResult<Real> dualIntersects;
    findIntersects(rawOffsetPline, dualRawOffsetPline, rawOffsetPlineSpatialIndex, dualIntersects);

    // using map rather than unordered map since we want to construct the slices in vertex index order
    // and we do so by looping through all intersects (required later when slices are stitched
    // together, because slices may not all form closed loops/polylines so must go in order of
    // indexes to ensure longest sitched results are formed)
    std::map<std::size_t, std::vector<Vector2<Real>>> intersectsLookup;

    if (!originalPline.isClosed()) {
        // find intersects between circles generated at original open polyline end points and raw offset
        // polyline
        std::vector<std::pair<std::size_t, Vector2<Real>>> intersects;
        internal::offsetCircleIntersectsWithPline(rawOffsetPline, offset, originalPline[0].pos(),
            rawOffsetPlineSpatialIndex, intersects);
        internal::offsetCircleIntersectsWithPline(rawOffsetPline, offset,
            originalPline.lastVertex().pos(),
            rawOffsetPlineSpatialIndex, intersects);

        for (auto const& pair : intersects) {
            // Keep intersection only if its not a tangent intersection with the raw offset // <---
            if (!Vector2.fuzzyEqual(pair.second, rawOffsetPline[0].pos()) && !Vector2.fuzzyEqual(pair.second, rawOffsetPline.lastVertex().pos())) {
                intersectsLookup[pair.first].push_back(pair.second);
            }
        }
    }

    // ...
}

from cavaliercontours.

jbuckmccready avatar jbuckmccready commented on May 25, 2024

Yep, looks right to me, thanks for finding this.

from cavaliercontours.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.