How to draw the cubic Bézier curve?

How to calculate the length, and other info, programatically of a cubic Bézier curve?

  • I have a cubic Bézier curve, and I need to programatically calculate some information about it. In particular: - The length; - The x,y position of a point on the Bézier curve given the percentage from the start of it (i.e., 0.0 would be at the start, 0.5 would be the exact centre of the curve, 1.0 at the end); - The gradient of the curve at a given point, again between 0 and 1; - Not so important, but also the maximum gradient of the curve would be useful. I've tried integrating a Bézier curve before, but I was unable to; I hear that might not be possible, and so a recursive function to calculate the length might be the only way. As for the other points, I'm not sure. Thanks!

  • Answer:

    First cut at this problem: You can get approximations to all of these by sampling. Generate 1000 points on your curve for instance. The length is the sum of the 999 distances. The (x,y) position could be from a lookup table combined with interpolation techniques. Same thing with the gradient. You could refine the approximations by doing finer sampling, generating more intermediate points, once you know the rough region you want to sample.

nerdcms at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

First cut at this problem: You can get approximations to all of these by sampling. Generate 1000 points on your curve for instance. The length is the sum of the 999 distances. The (x,y) position could be from a lookup table combined with interpolation techniques. Same thing with the gradient. You could refine the approximations by doing finer sampling, generating more intermediate points, once you know the rough region you want to sample.

Randy P

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.