Comments (5)
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:
- It ensures the resulting offset is never closer to the original polyline than the offset value given.
- The resulting offset polyline is not self intersecting if the input polyline was not self intersecting.
- 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).
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.
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.
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?
from cavaliercontours.
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.
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.
Yep, looks right to me, thanks for finding this.
from cavaliercontours.
Related Issues (20)
- IMPORTANT: Development is continuing in Rust (with C FFI)
- Can you implement `MinkowskiSum`? HOT 1
- can you explain the parameters HOT 1
- How to make a contour with sharp corners instead of arcs? HOT 4
- Support polyline with multiple offsets HOT 1
- incorrect bulge value in some cases HOT 4
- Apparently incorrect output using ParallelOffsetIslands HOT 1
- 3D Offset on surface HOT 2
- boolean operation HOT 1
- Offset bug? HOT 12
- Shifting the input polyline produces very different results HOT 8
- bulge value error when bulge>1? HOT 2
- How to scan a polyline / multipolyline HOT 1
- project compile
- generate offset contour of a line segment HOT 2
- Performance Comparison of Difference Calculation in C++ and C#
- New incorrect case HOT 3
- Question: add fillets to contour possible? HOT 1
- Self-intersection HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cavaliercontours.