Skip to content
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

Find self-intersection points of a trail #261

Open
byorgey opened this issue Sep 12, 2015 · 7 comments
Open

Find self-intersection points of a trail #261

byorgey opened this issue Sep 12, 2015 · 7 comments

Comments

@byorgey
Copy link
Member

byorgey commented Sep 12, 2015

Using functions like intersectPointsT it is possible to find the points where two trails intersect. It would be nice to have a function to find self-intersection points of a single trail. Passing the same trail twice to intersectPointsT will not work since they intersect at every point.

@byorgey
Copy link
Member Author

byorgey commented Sep 12, 2015

See #207 which this might be useful for.

@kuribas
Copy link

kuribas commented Sep 23, 2016

You could split the bezier at vertical (or any) directions, then use the intersection functions on these.

@byorgey
Copy link
Member Author

byorgey commented Sep 27, 2016

@kuribas I am not sure I understand what you mean. If a trail has a self-intersection, splitting it at some point does not guarantee that the intersection will be between the two halves---it could still be a self-intersection of one of the two pieces. One can continue doing this recursively, of course, but I am not sure how you would know when to stop.

@kuribas
Copy link

kuribas commented Sep 27, 2016

If the curve doesn't turn more than 180 degrees, it cannot self-intersect (assuming no singularities).

@fryguybob
Copy link
Member

@kuribas do you have a precise method of computing this turn? For instance:

d :: Diagram B
d = fromSegments . (:[]) $ (bezier3 (4 ^& 5) ((-1) ^& 0) (4 ^& 4))

d' :: Diagram B
d' = fromSegments . (:[]) $ (bezier3 (4 ^& 5) ((-1) ^& (-1)) (4 ^& 4))

Here d has a loop and d' does not.

@byorgey
Copy link
Member Author

byorgey commented Sep 28, 2016

Oh! Now I think I understand. You mean to split the bezier at every point where the normal vector (or its negation) is equal to some fixed direction. Yes, I think that should work nicely. We don't even have to so subdivision etc. since finding the parameters to split on just amounts to solving a quadratic.

@kuribas
Copy link

kuribas commented Sep 28, 2016

yes. I use the derivative curve, but the idea is the same. For example B_x'(t) = 0 for vertical directions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants