Comment by sfink

Comment by sfink 3 days ago

6 replies

Awesome visualizations.

The part that I was expecting to see but didn't: how can you move at a constant speed? For the original purpose of positioning objects along a path, it doesn't matter. But when moving, you can see it's moving much more slowly at the beginning and end (mostly determined by the radius). What if I want it to travel at a constant rate? Or even apply an easing function to the speed?

I'm sure there's some fancy mathematical trick that would just do it. If I were only more comfortable with math... my handwavy sketch would be to compute the speed function by differentiating the formulas to get dx, dy, and dz and passing them through the Pythagorean equation, then reparameterize on a t' variable using the inverse of the speed function? Maybe? I feel like I'm speaking using words I don't understand.

Sharlin 3 days ago

For constant speed you need a so-called “Euclidean parameterization” where the t value is proportional to s, the Euclidean distance traveled (and thus no matter the value of t, if you add some dt it always works out to the same ds). This is super commonly needed when animating motion along all sorts of curves, as you might guess.

Unfortunately, there’s usually no closed-form solution for it, so we have to do it numerically. And for doing that there’s in general no better way than at each t, binary/interpolation search a dt that roughly corresponds to the ds that you want (start with the previous dt, it’s likely a very good approximation).

In practice, you’d do that once and store the results, basically approximating the curve as a polyline of evenly-spaced points– at least assuming that the curve itself isn’t changing over time!

  • Kennnan 3 days ago

    This pattern of stepping with different ds along a path has a lot of applications in control theory. Often we change the ds/dt ratio based on the known acceleration profile of a motor to minimize jerk and reach our destination as fast as possible.

    Generally this idea is called motion profiling: https://www.motioncontroltips.com/what-is-a-motion-profile/

meindnoch 3 days ago

>I'm sure there's some fancy mathematical trick that would just do it. If I were only more comfortable with math... my handwavy sketch would be to compute the speed function by differentiating the formulas to get dx, dy, and dz and passing them through the Pythagorean equation, then reparameterize on a t' variable using the inverse of the speed function? Maybe? I feel like I'm speaking using words I don't understand.

What you're looking for is called arc length parameterization. Basically, you need to compose the curve with the inverse of its arc length function. Aside from a few special curve families, closed-form solutions don't exist.

chaboud 3 days ago

The instinct to sort of slow t is right, as the governing functions are maintaining angular velocity with respect to t but scaling radius also with respect to t.

It’s sort of like an Archimedean spiral. So, yeah, if you parameterize velocity and make that constant, you’re in better shape. Note that the radius starts at zero, though, so something is going to have to deal with limits.

A simpler path following approximation (e.g., for a game) might be to just give an iterative system path and tangent targets with respect to Z and then provide an iterative constraint on velocity with some sort of basic tweening (e.g., new = a * old + (1 - a) * target). Then just drag the thing along Z, like bead toys for toddlers.

[removed] 3 days ago
[deleted]
damarberlari 3 days ago

thanks!

currently the path is expressed as function of (t), and it's the t that progressed at the constant speed.

so the cube will finished one loop at the same duration, and thats why it moves much slowly at the beginning and end, where distance of one loop is smaller.

I have to admit I made it that way because it's simpler to implement:D. Making it move at constant speed require some more works, but others have provided some solutions here so I think I'll try