17117f1b4Smrg
27117f1b4Smrg/*
37117f1b4Smrg * Mesa 3-D graphics library
47117f1b4Smrg *
57117f1b4Smrg * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
67117f1b4Smrg *
77117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
87117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
97117f1b4Smrg * to deal in the Software without restriction, including without limitation
107117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
117117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
127117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
137117f1b4Smrg *
147117f1b4Smrg * The above copyright notice and this permission notice shall be included
157117f1b4Smrg * in all copies or substantial portions of the Software.
167117f1b4Smrg *
177117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
187117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
197117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
247117f1b4Smrg */
257117f1b4Smrg
267117f1b4Smrg#ifndef _M_EVAL_H
277117f1b4Smrg#define _M_EVAL_H
287117f1b4Smrg
29c1f859d4Smrg#include "main/glheader.h"
307117f1b4Smrg
317117f1b4Smrgvoid _math_init_eval( void );
327117f1b4Smrg
337117f1b4Smrg
347117f1b4Smrg/*
357117f1b4Smrg * Horner scheme for Bezier curves
367117f1b4Smrg *
377117f1b4Smrg * Bezier curves can be computed via a Horner scheme.
387117f1b4Smrg * Horner is numerically less stable than the de Casteljau
397117f1b4Smrg * algorithm, but it is faster. For curves of degree n
407117f1b4Smrg * the complexity of Horner is O(n) and de Casteljau is O(n^2).
417117f1b4Smrg * Since stability is not important for displaying curve
427117f1b4Smrg * points I decided to use the Horner scheme.
437117f1b4Smrg *
447117f1b4Smrg * A cubic Bezier curve with control points b0, b1, b2, b3 can be
457117f1b4Smrg * written as
467117f1b4Smrg *
477117f1b4Smrg *        (([3]        [3]     )     [3]       )     [3]
487117f1b4Smrg * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3
497117f1b4Smrg *
507117f1b4Smrg *                                           [n]
517117f1b4Smrg * where s=1-t and the binomial coefficients [i]. These can
527117f1b4Smrg * be computed iteratively using the identity:
537117f1b4Smrg *
547117f1b4Smrg * [n]               [n  ]             [n]
557117f1b4Smrg * [i] = (n-i+1)/i * [i-1]     and     [0] = 1
567117f1b4Smrg */
577117f1b4Smrg
587117f1b4Smrg
597117f1b4Smrgvoid
607117f1b4Smrg_math_horner_bezier_curve(const GLfloat *cp, GLfloat *out, GLfloat t,
617117f1b4Smrg			  GLuint dim, GLuint order);
627117f1b4Smrg
637117f1b4Smrg
647117f1b4Smrg/*
657117f1b4Smrg * Tensor product Bezier surfaces
667117f1b4Smrg *
677117f1b4Smrg * Again the Horner scheme is used to compute a point on a
687117f1b4Smrg * TP Bezier surface. First a control polygon for a curve
697117f1b4Smrg * on the surface in one parameter direction is computed,
707117f1b4Smrg * then the point on the curve for the other parameter
717117f1b4Smrg * direction is evaluated.
727117f1b4Smrg *
737117f1b4Smrg * To store the curve control polygon additional storage
747117f1b4Smrg * for max(uorder,vorder) points is needed in the
757117f1b4Smrg * control net cn.
767117f1b4Smrg */
777117f1b4Smrg
787117f1b4Smrgvoid
797117f1b4Smrg_math_horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v,
807117f1b4Smrg			 GLuint dim, GLuint uorder, GLuint vorder);
817117f1b4Smrg
827117f1b4Smrg
837117f1b4Smrg/*
847117f1b4Smrg * The direct de Casteljau algorithm is used when a point on the
857117f1b4Smrg * surface and the tangent directions spanning the tangent plane
867117f1b4Smrg * should be computed (this is needed to compute normals to the
877117f1b4Smrg * surface). In this case the de Casteljau algorithm approach is
887117f1b4Smrg * nicer because a point and the partial derivatives can be computed
897117f1b4Smrg * at the same time. To get the correct tangent length du and dv
907117f1b4Smrg * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1.
917117f1b4Smrg * Since only the directions are needed, this scaling step is omitted.
927117f1b4Smrg *
937117f1b4Smrg * De Casteljau needs additional storage for uorder*vorder
947117f1b4Smrg * values in the control net cn.
957117f1b4Smrg */
967117f1b4Smrg
977117f1b4Smrgvoid
987117f1b4Smrg_math_de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv,
997117f1b4Smrg			GLfloat u, GLfloat v, GLuint dim,
1007117f1b4Smrg			GLuint uorder, GLuint vorder);
1017117f1b4Smrg
1027117f1b4Smrg
1037117f1b4Smrg#endif
104