-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent intersection points with line and path #47
Comments
Thanks @bob-pasabi for reporting this. Due to the holidays, it may be a few days before I'll be able to look into this. Hopefully it's an easy fix :) |
@bob-pasabi, I believe I have a fix: I need to write some proper tests and clean things up a bit. Once all of that is done, I'll push a new release and close this issue. Thanks again for reporting this! |
Thats great, no rush. Will give it a go once it's pushed and will let you know. |
Fwiw, the problem is here: https://github.com/thelonious/kld-intersections/blob/development/lib/Intersection.js#L83-L110 here is my fix: function restrictPointsToArc(intersections, center, radiusX, radiusY, startRadians, endRadians) {
if (intersections.points.length === 0) {
return intersections;
}
const result = new Intersection("No Intersection");
//swap if end is lower, so start is always the lower one
if (endRadians < startRadians) {
[startRadians, endRadians] = [endRadians, startRadians];
}
//move everything to the positive domain, simultaniously
if (startRadians < 0 || endRadians <0) {
startRadians += TWO_PI;
endRadians += TWO_PI;
}
for (const p of intersections.points) {
let a = normalizeAngle(UNIT_X.angleBetween(Vector2D.fromPoints(center, p)));
//a angle smaller than start, it may still be between
//this happens if end > TWO_PI
if (a < startRadians) a += TWO_PI;
if (startRadians <= a && a <= endRadians) {
result.appendPoint(p);
}
}
if (result.points.length > 0) {
result.status = "Intersection";
}
return result;
} |
Hi @rikkertkoppes. No, unfortunately, I thought I had a fix, but it ended up breaking other cases. Yes indeed, the problem is in that code, specifically, where I'm trying to canonicalize the starting and ending angles which are used to filter the results. I'm in the middle of a release right now, so I'm not sure when I'll get to this. Of course, if you find a fix, I would gladly accept a PR. My apologies for the trouble and delay |
The above fix does seem to work, math seems right to me too. I'll see if I can find some time to add tests and commit a pr |
Oh, OK. Great! I will give this a try. I can take care of committing it. No need for a PR |
Yeah, that looks like its working well. If you can, would you test using the development branch? I had some visual tests that I was using. Here's the process I used: cd kld-intersections
git checkout development
git pull origin development
npm update
npm run rollup
http-server . Opened browser to
If everything looks good for you, I can push a new release. Thanks for the help! |
This was my reasoning:
These are the steps then:
So we now always have 0 < s < e, and e may be > TWO_PI. The angle we need to check (a) is now normalized: 0 < a < TWO_PI
|
@bob-pasabi @rikkertkoppes: I've pushed 0.7.0 with rikkertkoppes fixes. Thanks so much for reporting the issue and, especially, for providing a fix. That's a big help! I'm closing this, but if you see any other related issues, please feel free to re-open |
Hi, I think I bumped into a very similar problem using I am looking for intersection between circle #0 and the yellow path.
It looks very strange to me: it is detecting intersections with other two circles, that are not even visible to kld. Same issue with different geometries: This is the strangest case I found: it detects 2 fake intersections and then it detects two actual ones: To solve I found a workaround, that is to transform the path into a polygon, sampling it with a certain precision rate. Then I look for intersections with the polygon, which is working great!
I have some performances issue to deal with now (I have to check many many shapes), but at least it is working correctly. |
What comprises the yellow path? Looks like arcs and beziers? Can you provide the geometries or a test repo? |
@iosonosempreio, I know @rikkertkoppes asked already, but if you can provide an example that recreates the original issue, that would be really helpful. |
Hi, sorry for keeping you guys waiting.
You should be able to reproduce it using the SVG code I provided plus these KLD functions, for everyone of the circles above:
Generate circles using this data:
|
I’m having an issue getting intersections to work correctly with a path and a line. I’ve been using kld-intersections to do intersections for my custom polygon nodes and it works great. I’ve been adding a cloud node to the DAG and wanted to get the edge arrows to line up nicely with the edges of the cloud but I can’t seem to get reliable intersection points for the path.
If I take a cloud path
And a line through it like
It won’t pick up the intersections on the arc part. If I move the line it may pick up intersections inside the cloud rather that along its path.
I'm not sure if I'm doing something wrong here, I've seen way more complicated path and line intersections working so I'm unsure what is going on.
(circles are drawn for reported intersections, I added a rect to the background as well just to check the line was ok)
The text was updated successfully, but these errors were encountered: