#### Archived

This topic is now archived and is closed to further replies.

# Length of a cubic interpolation curve

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

## Recommended Posts

Hi. I have the following problem. I have a number of points on the screen (2D) and I want my object to go from through those points smoothly. In order to do that I use the following cubic interpolation function
  CubicInterpolate(float v0, float v1, float v2, float v3, float x) { float P = (v3 - v2) - (v0 - v1); float Q = (v0 - v1) - P; float R = v2 - v0; float S = v1; return (P*x * P*x * P*x) + (Q*x * Q*x) + (R*x) + S; } 
Where v0 - v3 are points on the curve and x is a value between 0 and 1 (0 means we''re at v1, 1 means we''re at v2). The problem I have is that as my object moves I increment x by a constant and the speed of the object changes depending on the distance between the points. I want the speed to be uniform. In order to do that I would have to divide the constant by the length of the curve, but I have no idea how to figure it out. I know the length equals the definite integral of the function between 1 and 2, but I don''t want to spend time writing code to calculate the integral. Can someone give me code I could use to calculate the length of the curve? Or are there any other methods I could use to make the speend constant? Thanks.

##### Share on other sites
Correct me if I''m wrong, but I think you can just calculate the primitive of the funtion for the cubic interpolation curve by hand and then use that function in an algorithm. You simply need to find the primitive F(x) for f(x) = (P*x)3 + (Q*x)2 + (R*x) + S. Then the length of the curve between v1 and v2 is: F(v2) - F(v1). Not that difficult a task, I think. But this is all AFAIK, I''m no expert.

##### Share on other sites
The length of the curve=definite integral of (1+(f'')^2)^.5

In general this integral is usually impossible to solve
exactly so you have to compute it numerically.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013301
×