0

Situation looks as follows:

The situation

The SDK I'm working with represents position on a spline as a 0-1 value. From that position I can get (x,y,z) coords of a point. I start with point A, let's say at 0.5 on the spline and some (xa,ya,za) position in space. I want to now move along the spline (so subtracting from that 0.5) until i get B (xb,yb,zb) so that the distance (A,B) is a given d. The difference between the spline position of A(0.5) and B(x) is the n I'm looking for. My naive approach was to get start = n/length_of_the_spline, set a new point at 0.5 - start and then in a subtract 0.001 from it, get the (x,y,z) position, measure the distance of that point from A and if it's more that d, try again until it is. This I think is a rather wasteful way of doing it.

Can anyone point me to some algorithm that could help me? I'm not able to get the parametric representation of the spline, so can't math out where a circle intersects the spline. What I can do is traverse the spline, get (x,y,z) coords and measure distances.

Here's what this is for (current python script inside) https://www.reddit.com/r/Cinema4D/comments/vyuyiu/chains_with_python/

Will Ness
  • 70,110
  • 9
  • 98
  • 181
  • Don't post code and images outside SO. – Jean-Baptiste Yunès Jul 28 '22 at 09:12
  • binary search on spline's parameter, for starters. – Will Ness Jul 28 '22 at 09:53
  • ...each time measuring the distance from the point to the target point. to not get trapped in a local minimum, initially put N points along the spline at equal delta-parameter values, and thus find the interval of interest so that its two end points have different signs of the value `distance - Radius`. If there is no such interval, increase N=2*N and try again. or indeed start from your stating point `A` and go along the spline by some increment, possibly increasing it `incr=1.1*incr` on each step. or something. it's a search problem. – Will Ness Jul 28 '22 at 10:29
  • (IOW you're asking about circle-spline intersection. try googling for that, maybe). – Will Ness Jul 28 '22 at 10:34
  • Will Ness - That was my first thought but 1. It would be a sphere spline intersection 2. The SDK I'm using doesn't allow me to get a parametric version of the spline. – Andrew Zmurowski Jul 28 '22 at 11:27
  • (there's no notifications without the `@` ping) 1. you just calculate the distance between two points, whether in 2D or 3D. 2. you can generate points along the spline in _some_ way, right? if not by parameter then by, say, distance along the spline? actually, you do say "represents position on a spline as a 0-1 value" which _is_ a parameter. – Will Ness Jul 28 '22 at 12:31
  • so you calculate `B_i` points and their distances to `A` at 0.1, 0.2, 0.3, 0.4, 0.6, ... 1.0, select two points with the opposite signs of `D_i - R`, say `0.2, 0.3`, then go by `0.01` increments inside _that_ segment, again select the interval with the flipped signs of the difference, and so on and so forth, stopping when you're satisfied with the precision. or go by binary splits once the interval is found the first time. or combine that with the secant method. ([here's](https://stackoverflow.com/a/36368290/849891) what I have in mind.) – Will Ness Jul 28 '22 at 12:35
  • (correction, missed B_0 at 0.0, of course) – Will Ness Jul 28 '22 at 12:48
  • @WillNess - this is exactly what I wanted to know. So get one point to far and one to close and then close in on the value between. Great. – Andrew Zmurowski Jul 28 '22 at 13:08

0 Answers0