equal object spacing on a curve

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

Recommended Posts

Hi everybody. I have a unique problem I need some assistance with. In my game, I have a set of objects traveling along a curved line, but they need to be equally spaced apart, in terms of pixels. It is easy to have the objects move along the curved line, but getting them to equal spacing has been the really tricky part. I have done a preliminary implementation which works, but is also not terribly efficient in terms of wasting memory. Basically, I have an array that stores the location values for every object on this line. All of the objects follow the front object, which has a velocity that I can manipulate to follow a certain path. If the velocity is set to move it 1 pixel in 1 second, then the new position is added to the array, and all the positions of the other objects are shifted over. The way I made it to work with equal spacing is that if the object needs to move 2 pixels in a second, I actually move it by 1 pixel after 500ms, then another pixel after 500ms, and in both cases the positions of the objects following the leader are moved by 1 pixel as well. It would be nice to get this to work more efficiently by using catmull-rom interpolation, but I have run out of ideas on how to find 't' for the objects that are following the leader. If anybody has any ideas, or can point me in the right direction, I would be very greatful indeed.

Share on other sites
Are you sure that you have to work in pixels? What platform are you developing for? (More typically, these sorts of computations are done using floating point variables, the values of which are then converted to pixel coordinates, if necessary, for rendering purposes.)

As for the problem you describe, it sounds like you're looking for 'arc-length reparameterization'.

Share on other sites
Well, I need to work in pixels because I'm doing this in 2D, and I need equal spacing so that I can line up some textures properly. Technically I am working in floating point vars, but those just directly translate to screen pixel coords. If it helps, I'm using XNA for this project.

Today, I was looking at the formula to find the arc-length of a curve, and I'm pretty sure I can implement that, but it looks very computationally expensive, especially when i have say, 200 objects on the line. Also, if it helps, I don't need it to be dynamic, that is, I could have the path be the same every time (I'll just have multiple different paths, with different starting points).

Maybe it'll help if I explain exactly what I'm doing, maybe my whole reason for doing this is wrong. I have a line, that is made up of some arbitrary number of sections, say 20. These sections are are drawn with textures of size 32x32, and the spacing and drawing is done so that it looks like a smooth line, even when there are curves in the path. This line travels along a path determined by the front object, which has a velocity that I can manipulate. Then, it hits an object, the front section is destroyed, and the line now contains 19 sections. Maybe there's a better way of doing this that I haven't thought of yet. I have it mostly working now, it's just not the nicest implementation, and it takes a long time to design the path of the line in advance. (Since I can only manipulate the velocity, I need to determine at precisely what moment in time the velocity needs to change, and to what.)

Share on other sites
Quote:
 Original post by goreckmWell, I need to work in pixels because I'm doing this in 2D...
That doesn't really follow (unless there's something unusual about how XNA handles things - I haven't used the API myself). With any modern graphics API, you should be able to work with floating-point coordinates regardless of whether it's 2-d or 3-d.

Share on other sites
David Eberly has a discussion of arc-length parameterization of curves at his website, here:

Moving Along a Curve with Specified Speed

Recognize that if you specify a speed, say, 5 meters per second, and you want to move along the curve at that speed, then you have to know how to determine points along the curve that are uniformly distributed in terms of the length along the curve. Now, if you represent the curve in pixel coordinates, then you can (approximately) compute the arc length in pixels.

Hope that helps!

Share on other sites
Actually that's very useful. Thanks!

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• Forum Statistics

• Total Topics
634044
• Total Posts
3015215
×