• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
GuyWithBeard

Coefficients for bezier curves

7 posts in this topic

I have been working with Cubic and Quadratic bezier curves for the past week, and one thing that I am still not sure about is how to get the polynomial coefficients from the control points. For example, a cubic bezier has the formula A*t^3 + B*t^2 + C*t + D and a quadratic one has A*t^2 + B*t + C. The cubic bezier is defined by the end points P0 and P3, and the control points P1 and P2. The quadratic one is just P0, P1 and P2. http://floris.briolas.nl/floris/2009/10/bounding-box-of-cubic-bezier/ says that the coefficients for the cubic bezier can be calculated like:
 
m_DX = m_P0.x;
m_CX = 3.0f * ( m_P1.x - m_P0.x );
m_BX = ( 3.0f * m_P2.x ) - ( 6.0f * m_P1.x ) + ( 3.0f * m_P0.x );
m_AX = m_P3.x - ( 3.0f * m_P2.x ) + ( 3.0f * m_P1.x ) - m_P0.x;
 
These coefficients can be plugged into the formula A*t^3 + B*t^2 + C*t + D and it works, so they seem to be okay. I am not sure how those coefficients were derived though. Can anyone explain this to me? Also, I would need to calculate the same coefficients for a quadratic bezier.
 
Thanks!
0

Share this post


Link to post
Share on other sites

You start from the parametric Bézier curve formula and rewrite the terms until you obtain the desired formula. This is simple algebra, nothing complicated. For example, for the quadratic case:

 

acv2qqk.png

 

The derivation in the cubic case is similar. But I have always found the Bézier formula a much more useful formulation. Why do you want the coefficients of the polynomial?

 

EDIT: corrected the formula..

Edited by apatriarca
1

Share this post


Link to post
Share on other sites

Thanks, I'll have to look through that. I am using the coefficients for several things. For example, to get the x at a given t I can just do:

 

float Curve::QuadraticBezierSegment::getXAtT( float t ) const
{
// A*t^2 + B*t + C
return ( m_AX * t * t ) + ( m_BX * t ) + m_CX; 
}
 

There might be some other way to do that too, I am not sure. Also, if I take the derivative of the formula and plug in the coefficients I can solve it and get local extrema, ie. the bounds of the curve. Again, I am not a math person, and there might be other ways to do this. If some come to mind, please feel free to share smile.png

Edited by GuyWithBeard
0

Share this post


Link to post
Share on other sites

To get a point in a Bézier curve the standard method is known as De Casteljau's algorithm. You iteratively linearly interpolate all control points until you find a single point. This is more robust than evaluating your formula. It is also useful to get a better geometric intuition. You may also be interested in the Horner's Method which is a more robust way to evaluate your polynomial. You write C + t*(B + t*A) instead of C + t*B + t*t*A in the quadratic case.

 

The derivative of a Bézier curve is a lower degree Bézier curve. The derivative of a quadratic Bézier curve is thus a segment and of a cubic Bézier curve is a quadratic Bézier curve. The proof use the following result on the Bernstein polynomials (used to define the equation of a Bézier curve).

 

clnba7b.png

 

The control points of the derivative curve are indeed the points a9lcbze.png for all i from 0 to n-1.

 

If all you want is however to get some bounds on the curve, a Bézier curve also have the property to be contained in the convex hull of its points. It can be useful to easily discard curve pairs for collision for example. There also exists interative methods to compute intersections of Bézier curve using this method (or something similar).

2

Share this post


Link to post
Share on other sites

(Disclaimer: sorry if the LaTeX equations don't come out right; I've had issues!)

 

apatriarca's formula for the derivative of a Bezier curve is mostly right, but you need to divide the control points by the interval of the curve. The formula for the derivative's control points is Di = n/(t1 - t0) * (Pi+1-Pi). This isn't a problem if the parameter domain for the Bezier curve is [0,1], but if it's something else, then you have to divide by the interval.

 

If you want to convert a Bezier curve to a power basis polynomial, you need to convert the Bezier curve into an explicit Bezier curve (one where the x-coordinates of the curve are evenly spaced, such as below:

 

[attachment=15778:explicit.jpg]

 

Then you can express this as a Bernstein polynomial [eqn]y = \sum_{i=0}^n y_i B_i^n (t)[\eqn], where x = t. The closed-form conversion between Bernstein to power basis is given as [eqn]p_i = \sum_{k=0}^i b_k \binom{n}{i} \binom{i}{k} (-1)^{i-k}[\eqn].

 

My real question is: why you would want to convert to a polynomial when you can probably do what you want in the Bernstein basis?

0

Share this post


Link to post
Share on other sites

In my previous reply I was only considering Bézier curves in which t vary uniformly in the [0, 1] interval. If you change the parametrization you clearly have to adjust the derivative, but this does not make my result wrong in any way. More complicated parametrizations are actually also possible. What if I want to use t = sin(s) with s in [0, pi/2]? The (support of the) curve clearly remains the same, but the velocity/derivative is now different.

0

Share this post


Link to post
Share on other sites

apatriarca, I didn't mean to say that your formula was incorrect. I just wanted to add that the interval of the curve matters in the derivative, you know, for completeness.

0

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0