-
Notifications
You must be signed in to change notification settings - Fork 1
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
Getting interpolated values at fractions between knots #3
Comments
Happy to hear this. In src/centripetal/arcbased.jl there is this function:
I could use the same automagical generation of "So f(0) would be knot 1, f(1) would be knot 2 and f(0.5) would be halfway between the two." I am happy to export / add + export what will work well for you. Could you show me an example of some successive data/function points [xs and f(x)s]? |
If I understand correctly, you always need at least four points to have a spline, that is fine with me per se, but I would still like to have the option to interpolate with different timings between pairs of knots, given that the overall spline has at least four points. Let's say I have four camera positions and fit a spline through them, then maybe I want to first animate from point 1 to 2 quite fast, but then go slower to 3, etc. That's why I need to know the arc lengths between every pair of knots, as well as the ability to interpolate the positions at arbitrary fractions. Does |
|
In the README, there is a description of using interpoint spacing to govern the number of intermediating points [arclength relative allocations] (https://github.com/JeffreySarnoff/CatmullRom.jl#arclength-relative-allocation). Is this the sort of |
I can give you the ability to interpolate for whatever % of the interknot distances you choose. That requires some coding. If I understand correctly, you want to give a sequence of knots and for each adjacent pair obtain the arc distance between them and the splined coordinate halfway between them. It is easy to obtain a halfway-x by linear interpolation, it is less easy to move halfway along the spline and then return the corresponding x. |
Halfway was just a random example, I need any percentage between two knots. Depending on the number of frames for an animation and the chosen easing function, the interpolated points will be spaced apart in arbitrary ways, but always be specified by their fraction along the spline. That's because the speed of a dot moving along the spline depends on the distance it travels, so depending on the easing function the animation uses I might need to calculate positions for each entry in let's say a vector of [0, 0.1, 0.25, 0.6, 0.9, 1] spline length fractions. That could be one animation. |
That is no problem. How about linear interpolation for the xs? |
Actually I get a better approximation using the spline length fractions to generate new knots and use those knots to find a better than linear approximation to the xs. |
which xs do you mean? the x coordinates of my knots? I don't know much about the mathematics behind the splines if you're referring to something there |
I do mean the x coordinates of your knots and the x coordinates of you spline length fractions.
|
Please show me a short set of coordinates (your initial points, in sequence) .. 6 is enough. You can estimate them, or make them up if that easier. |
note to myself:
|
I would do something like this: cameracoords = [
(0, 0, 0),
(0, 10, 0),
(0, 11, 3),
(3, 12, 3),
(3, 13, 0),
(0, 14, 0),
(0, 20, 0),
]
anim = CatmullAnimation(cameracoords, timestamps_for_knots, easingfunction)
dt = 1/30
timestamps = 0:dt:5
positions = at.(anim, timestamps) This would be going up, then something like an upward spiral and then up again. So I would expect one spline to go through all these points, but the spline shape doesn't yet determine the speed of the animation. This I would control with easings functions and time stamps. |
In your example, |
yes I think that's how I would implement it |
There is a bug that appears using this with Julia v1.2+. I have to fix that first. Standby :). |
Fixed. (Actually your input brought something to light, so thanks for that). |
that's good :) thank you, so does that mean there's now a function that I can use or was this more of a preliminary step? |
preliminary, necessary. I need to play around a little and see what is easiest to use, then export that. |
You could start playing with the following. It will become cleaner for use.
you will need this function (it will be in the next revision of the package)
You want to work with the polynomial expressions of the spline segments directly.
If you have 12 [x,y,z] coordinates,
|
Ok I've tried this out a little bit in 2D so I could plot what's going on. I don't yet know how to access the parts of the splines connecting the 1st and 2nd as well as n-1th and nth spline. Is there a trick to getting these polys? Now I see that the spacing of uniformly spaced values fed into the polys is not uniform anymore, I think I would want uniform so that the speed on the spline doesn't depend on its curvature. I'll have to fiddle with this a bit. This is what I tried: twod_coords = [
(0, 0),
(2, 0),
(2, 1),
(1, 0.5),
(0.5, 2)]
coordvec = coordvecs(twod_coords)
polys = catmullrom_polys(coordvec)
PyPlot.close_figs()
figure()
scatter(first.(twod_coords), (x->x[2]).(twod_coords))
x_poly1 = polyval(polys[1, 1], 0:0.1:1)
y_poly1 = polyval(polys[1, 2], 0:0.1:1)
scatter(x_poly1, y_poly1, alpha=0.5)
x_poly2 = polyval(polys[2, 1], 0:0.1:1)
y_poly2 = polyval(polys[2, 2], 0:0.1:1)
scatter(x_poly2, y_poly2, alpha=0.5)
gcf() |
good progress -- there is a function to help you with the extremal splines, but first: what you want with respect to uniform speed .. is that uniform distances along the |
I mean uniform movement along the splines, like a car travelling with constant speed on a winding road. If I have uniform movement on each partial spline I also have uniform movement along the full spline. I would preferably want both versions, depending on the use case. |
That is, I have the full spline if I can generate uniformly spaced values on each partial spline and know the length of each partial spline as well |
I have been traveling and will travelling through next week. I am looking into supporting your need, although I do not expect to do much until I return. |
Hi Jeffrey,
I thought about adding your Catmull-Rom splines to my Animations.jl package, for things like camera trajectories through space for example. What I would need is a function to get the point that lies on the spline between two knots at a certain fraction. So f(0) would be knot 1, f(1) would be knot 2 and f(0.5) would be halfway between the two. If I understand correctly, the two functions that your package offers generate lots of points at equal spacing, but is my request also possible? Also, knowing the arc length between two points beforehand would be useful, in order to control animation speed separately.
Thanks for your help,
Julius
The text was updated successfully, but these errors were encountered: