Jump to content
• Advertisement

# Creating smooth quadric bezier curves for any length and angle?

## Recommended Posts

Hi

I have a basic setup currently where i create a quadratic bezier curve, and then i do 100 steps across the curve to calculate its distance. And from that i do distance / 3 to give me the total number of segments.

Its pretty quick but its not a good solution for very large distances (too many segments) and then for very small distances (too few segments).

Here is a visual issue of the problem:

7 looks reasonable (though i actually think it computed 6 my mistake), but for something much shorter 2 simply doesn't cut it neither would 3 or 4 to be honest.

So i am wondering what is a common way to balance this so they are smooth regardless of length and sharpness of the angle ?

I use C# but I'm just looking for a logical approach here not how to implement it in code since i'm sure i can handle that myself

Thanks in advance.

#### Share this post

##### Share on other sites
Advertisement
Posted (edited)

Getting the arc length of a Bezier curve is a non-trivial problem. You can certainly estimate it via length of a polyline, but as you found out there have to be better ways. Which way you take really depends though on your desired level of accuracy, but numerical integration is the way to go here.

One interesting way you might have success with is detailed by Mike "Pomax" Kamermans here. He uses Gaussian quadrature to estimate the length of the Bezier curve. His explanation of how this works is good. I'm not sure how familiar you are with the math (Wikipedia is actually good at explaining Gauss quadrature), but I would highlight a couple of things just in case:

• The components of a Bezier curve B(x(t), y(t)) are just Bernstein polynomials x(t) and y(t) (or if you prefer to think of them as such, 1-D Bezier curves). This is important because they just evaluate to numbers, not points or vectors.
• You can take the derivatives of Bernstein polynomials the same way you do for Bezier curves. This will help with constructing the function that the Gauss quadrature will use.
• For a degree-n non-rational Bezier curve, the derivative will be degree-(n-1). However, if your Bezier curve is rational (meaning the control point weights are something other than 1), then the derivative will be degree-(2n) (Section 2.7 of the material here).
• Gaussian quadrature is exact only for polynomials of degree-(2m-1), where m is the number of Gaussian points to be used. For quadratic curves (degree-2), you can probably get away with only using 2 Gauss points. However, the function used by the Gauss quadrature is the square root of a polynomial that's degree-4. I'm an engineer and not a mathematician, but I have the feeling the resulting function can't necessarily be said to be degree-2. I personally would be safe and plan on it being a degree-4, which means that you should use 3 Gauss points at least.
• Gauss quadrature is defined over the interval [-1,1]. Bezier curves are defined over the interval [0,1], so just remember that when reading Pomax's explanation.

I've also seen a variant of this technique using Clenshaw-Curtis integration and an approximation of the Bezier curve arc length function using Chebyshev polynomials and it works as well. Again, it depends highly on your use case and your desired accuracy.

Edited by cadjunkie
Edited for accuracy.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011473
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!