1848b8605Smrg 2848b8605Smrg/* 3848b8605Smrg * Mesa 3-D graphics library 4848b8605Smrg * 5848b8605Smrg * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 6848b8605Smrg * 7848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 8848b8605Smrg * copy of this software and associated documentation files (the "Software"), 9848b8605Smrg * to deal in the Software without restriction, including without limitation 10848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 12848b8605Smrg * Software is furnished to do so, subject to the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice shall be included 15848b8605Smrg * in all copies or substantial portions of the Software. 16848b8605Smrg * 17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 24848b8605Smrg */ 25848b8605Smrg 26848b8605Smrg#ifndef _M_EVAL_H 27848b8605Smrg#define _M_EVAL_H 28848b8605Smrg 29848b8605Smrg#include "main/glheader.h" 30848b8605Smrg 31848b8605Smrgvoid _math_init_eval( void ); 32848b8605Smrg 33848b8605Smrg 34848b8605Smrg/* 35848b8605Smrg * Horner scheme for Bezier curves 36848b8605Smrg * 37848b8605Smrg * Bezier curves can be computed via a Horner scheme. 38848b8605Smrg * Horner is numerically less stable than the de Casteljau 39848b8605Smrg * algorithm, but it is faster. For curves of degree n 40848b8605Smrg * the complexity of Horner is O(n) and de Casteljau is O(n^2). 41848b8605Smrg * Since stability is not important for displaying curve 42848b8605Smrg * points I decided to use the Horner scheme. 43848b8605Smrg * 44848b8605Smrg * A cubic Bezier curve with control points b0, b1, b2, b3 can be 45848b8605Smrg * written as 46848b8605Smrg * 47848b8605Smrg * (([3] [3] ) [3] ) [3] 48848b8605Smrg * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3 49848b8605Smrg * 50848b8605Smrg * [n] 51848b8605Smrg * where s=1-t and the binomial coefficients [i]. These can 52848b8605Smrg * be computed iteratively using the identity: 53848b8605Smrg * 54848b8605Smrg * [n] [n ] [n] 55848b8605Smrg * [i] = (n-i+1)/i * [i-1] and [0] = 1 56848b8605Smrg */ 57848b8605Smrg 58848b8605Smrg 59848b8605Smrgvoid 60848b8605Smrg_math_horner_bezier_curve(const GLfloat *cp, GLfloat *out, GLfloat t, 61848b8605Smrg GLuint dim, GLuint order); 62848b8605Smrg 63848b8605Smrg 64848b8605Smrg/* 65848b8605Smrg * Tensor product Bezier surfaces 66848b8605Smrg * 67848b8605Smrg * Again the Horner scheme is used to compute a point on a 68848b8605Smrg * TP Bezier surface. First a control polygon for a curve 69848b8605Smrg * on the surface in one parameter direction is computed, 70848b8605Smrg * then the point on the curve for the other parameter 71848b8605Smrg * direction is evaluated. 72848b8605Smrg * 73848b8605Smrg * To store the curve control polygon additional storage 74848b8605Smrg * for max(uorder,vorder) points is needed in the 75848b8605Smrg * control net cn. 76848b8605Smrg */ 77848b8605Smrg 78848b8605Smrgvoid 79848b8605Smrg_math_horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v, 80848b8605Smrg GLuint dim, GLuint uorder, GLuint vorder); 81848b8605Smrg 82848b8605Smrg 83848b8605Smrg/* 84848b8605Smrg * The direct de Casteljau algorithm is used when a point on the 85848b8605Smrg * surface and the tangent directions spanning the tangent plane 86848b8605Smrg * should be computed (this is needed to compute normals to the 87848b8605Smrg * surface). In this case the de Casteljau algorithm approach is 88848b8605Smrg * nicer because a point and the partial derivatives can be computed 89848b8605Smrg * at the same time. To get the correct tangent length du and dv 90848b8605Smrg * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. 91848b8605Smrg * Since only the directions are needed, this scaling step is omitted. 92848b8605Smrg * 93848b8605Smrg * De Casteljau needs additional storage for uorder*vorder 94848b8605Smrg * values in the control net cn. 95848b8605Smrg */ 96848b8605Smrg 97848b8605Smrgvoid 98848b8605Smrg_math_de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv, 99848b8605Smrg GLfloat u, GLfloat v, GLuint dim, 100848b8605Smrg GLuint uorder, GLuint vorder); 101848b8605Smrg 102848b8605Smrg 103848b8605Smrg#endif 104