This topic is 5408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently working on some simple particle effects, where the follow a series of hermite spline in 3d. Each segment though can be, of course, a different length. So when I move a particle along the path, it appears to move slower when on the shorter segments, and faster on the longer ones, because its movement is based on time. How could go about making the particles trace each spline segment at the same speed?

##### Share on other sites
People usually don't use splines to control particles. You give it a starting point and a direction vector who's length is it's speed.

Each frame, it's position is increased by direction times the time between each frame.

For gravity, each frame you can decrease the z part of the direction vector (assuming it's up) by 9.8 times the time between each frame.

For friction, you can decrease the direction vector by some small number times the direction times the time between each frame.

##### Share on other sites
I have to be honest, i don't understand much about splines.

But looking at it logically, one can easilly guess what's wrong in that picture.

Whenever a unit of time passes, you advance a percentage of the spline.
1 second passes, you advance 1% of the total distance of the spline, another second another 1%, and so on.
And that won't acheive what you want, because in a smaller spline that 1% will be a smaller distance, and in a big spline it will be a larger distance, that's why a particle looks like it's moving slower with a smaller spline, because is advancing smaller distances at a time.

What you need to do is advance a fixed amount of space for splines of all sizes.

Hope it helps

##### Share on other sites
Usually, your problem is solved the following way:
Say you've got 3 2D points like this:
                (2)                          (3)  (1)

with coordinates (x1,y1), (x2,y2), (x3,y3). Hermite splines are 3rd order polynomials, so you also need slopes in the points (1) and (3). The slopes can either be given as additional input or generated by (x2-x1,y2-y1) resp. (x3-x2,y3-y2). The slope in (2) should be automagically generated by the spline solver.

First, you need to generate support nodes in time. You've probably generated them equidistantly like (t1,t2,t3)=(0,0.5,1), but you better generate them like
t1 = 0
t2 = sqrt((x2-x1)^2+(y2-y1)^2)
t3 = t2 + sqrt((x3-x2)^2+(y3-y2)^2)
or in general
t1 = 0
t_n+1 = t_n + sqrt((x_n+1 - x_n)^2+(y_n+1 - y_n)^2)
Then, you compute two spline curves, one called Sx for the x-coordinates and one called Sy for the y-coordinates.
Sx fulfills
t      t1  t2  t3Sx(t)  x1  x2  x3

and Sy interpolates
t      t1  t2  t3Sy(t)  y1  y2  y3

Now, if you want to evaluate the particle along the spline curve, you just need to compute (Sx(t),Sy(t)).

3D goes analogously. I don't know how you actually compute the splines, but I hope this helps. The only trick is not to set the t's equidistantly but based on the distances between the nodes.

##### Share on other sites
You can break it down into small segments. Say s(t) is your spline, t is your current position along the spline and dt is your step size. So you can calculate the distance from s(t) to s(t+dt). That is an approximation of the arc length. You can check how good an approximation it is by checking the distance from s(t) to s(t+dt/2) to s(t+dt). You check how good each of those are by subdividing each of them as well. You have some tolerance for error. Each time you subdivide you split that tolerance in half. So that gives you a means to say when to stop subdividing.

##### Share on other sites
@smart_idiot,
I'm using splines because it allows me to easily moves particles in complex patterns. I want something more than just a fountain.

my function takes in the 2 endpoints and the 2 control points and a time value[0,1]. Resulting position in space is stored in a vector. I think lilbudywizer picked up more on what I thought of as well. I just couldn't think of how to calculate the length of each curve.

##### Share on other sites
I'm not going to tell you not to use splines, but I'm curious as to why you are doing so. Working splines in a particle system doesn't sound too processor friendly.

Would you mind telling us what your particle system is doing? If it's emulating anything real then there will be a suitable set of physical laws that apply. They would most likely be a bit kinder to your framerate too.

If you insist on using splines, a cheap way to find the length of the arc segments would be to count pixels. Of course, you would want to precalculate this rather than do it on the fly, but the idea goes as follows:
Find a suitably low incremental value for your parameter - one that can be used to plot the whole spline without any gaps, then iterate along your segment incrementing a 'length' counter for each new pixel added (you will want to ensure that no pixel is counted twice).
Although your result will only be an estimate to the actual length of the spline, it will be exactly accurate enough for your purposes (considering that you can't render between pixels).

##### Share on other sites
It's just something I wanted to do for fun. Using the editor that I'm making, you can set the points in your world to design a path. Then you could use whatever you want really to follow the path. Doesn't have to be for particles like my first intentions were. It's just a way to make an object follow a path.

• 13
• 18
• 29
• 11
• 20