Forum

Spline Intersection

Hallo guys! There is an easy way to calculate the X value of a spline, given the Y?
Let’s say, as I would calculate x=f(y)
(the pic here is just to show thast I need the interesction between the white Spline and the green line)

Intersection_2021.02.22-12.04.17

Intersection.v4p (11.4 KB)

Have a look at this patch:

\girlpower\VL\Curves\SamplingSplines.v4p

It compares two options for sampling bezier splines (not b-splines though). ArcLength is probably what you’d use if you can also use beziersplines instead of b-splines.

I’m actually using ArcLength (2d) but I don’t know how to calculate “Position on Curve” once I have Y

I mean, I can play with it until I obtain (x,Y) but how can I calculate “Position on Curve” automatically?

Intersection_2021.02.22-20.53.35

Intersection.v4p (15.3 KB)

This is actually not so easy to achieve. Also there can be multiple solutions as a spline might not yield a single y for a given x or vice versa.

I remember an iterative solution to this, an algorithm that just tries to get very close to the solution with a maximum error delta, so it will just try to approximate the solution and check in every given step how far it is still off, I think.

Woei shared a website with me once explaining this quite well, let me check if I can find it tomorrow

I was a bit faster than I thought, it’s called De Casteljau algorithm and I think it was this website. You might find implementations of it somewhere in C# probably, also it would be nice to patch it in VL

https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/de-casteljau.html

I used it once to (of course) sample a spline for a timeline … maybe it’s on some old hard drive still, I will post it if I find it.

indeed i was mistaken, arclength is not the solution here, but this should be describing a way: https://pomax.github.io/bezierinfo/#yforx

Ah yes, this site also looks familiar

two ways:
differentiation
integration