开发者

OpenGL: How to draw Bezier curve of degree higher then 8?

开发者 https://www.devze.com 2022-12-28 14:38 出处:网络
I am trying to draw high order Bezier Curve using OpenGL evaluators: glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 30, &points[0][0]);

I am trying to draw high order Bezier Curve using OpenGL evaluators:

glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 30, &points[0][0]);

glMapGrid1f(30, 0, 1);
glEvalMesh1(GL_LINE, 0, 30);

or

glBegin(GL_LINE_STRIP);
for (int i = 0; i <= 30; i++) 
  glEvalCoord1f((GLfloat) i/30.0);
glEnd();

When number开发者_运维知识库 of points exceeds 8, curve disappears. How to draw higher order Bezier curve using evaluators?


See the paper:

Watkins and Worsey, Degree reduction of Bézier curves. Computer-Aided Design. 20(7), Sept. 1988, 398-405.

What they do is convert the Bézier curve into Chebyshev polynomial form, so the last term of the polynomial has the least effect on the shape, drop the last term, and convert it back to Bézier form. If this produces too much error, the Bézier is subdivided and the process is run again.

This makes it very easy to convert the high order curve down to a cubic Bézier the system can natively render efficiently. I've used this method for a couple different situations, and it works well. One caveat though; the matrix equations in the paper have some typos. See:

Peterson, J., Letter to the Editor, CAD, 23(6), August 1991, p.460

for the corrected equations. Unfortunately CAD is an old-school academic journal, and so the papers aren't conveniently on-line. You'll need to dig them out of a library someplace, or pay the fine to get them from Elsevier.


By any chance are you get a GL_MAX_EVAL_ORDER error? Bezier curves become unstable at high degrees. I wouldn't be surprised if your OpenGL implementation just gave up.

You can use glGet with GL_MAX_EVAL_ORDER to see what your implementation maxes at. If you need something higher, you can always roll your own, which isn't too bad.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号