nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "../NuxCore.h" 00024 #include "MathFunctions.h" 00025 #include "Bezier.h" 00026 00027 namespace nux 00028 { 00029 00030 NUX_DECLSPEC_DLL t_double *Bernstein (t_int n, t_double t) 00031 { 00032 if (n < 0) 00033 { 00034 NUX_BREAK_ASM_INT3; 00035 } 00036 00037 t_double *bernstein; 00038 t_int i; 00039 00040 bernstein = new t_double[n+1]; 00041 00042 for (i = 0; i <= n; i++ ) 00043 { 00044 bernstein[i] = BinomialCoefficient (n, i) * PowerInt<t_double> (t, i) * PowerInt<t_double> (1.0 - t, n - i); 00045 } 00046 00047 return bernstein; 00048 } 00049 00050 NUX_DECLSPEC_DLL void Bezier_XY (t_int n, t_double t, t_double xcon[], t_double ycon[], t_double *xval, t_double *yval) 00051 { 00052 if (n < 0) 00053 { 00054 NUX_BREAK_ASM_INT3; 00055 } 00056 00057 double *bval; 00058 int i; 00059 00060 bval = Bernstein ( n, t ); 00061 00062 *xval = 0.0; 00063 00064 for ( i = 0; i <= n; i++ ) 00065 *xval = *xval + xcon[i] * bval[i]; 00066 00067 *yval = 0.0; 00068 00069 for ( i = 0; i <= n; i++ ) 00070 *yval = *yval + ycon[i] * bval[i]; 00071 00072 delete [] bval; 00073 } 00074 00075 NUX_DECLSPEC_DLL void Bezier_XYZ (t_int n, t_double t, t_double xcon[], t_double ycon[], t_double zcon[], t_double *xval, t_double *yval, t_double *zval) 00076 { 00077 if (n < 0) 00078 NUX_BREAK_ASM_INT3; 00079 00080 double *bval; 00081 int i; 00082 00083 bval = Bernstein ( n, t ); 00084 00085 *xval = 0.0; 00086 00087 for ( i = 0; i <= n; i++ ) 00088 *xval = *xval + xcon[i] * bval[i]; 00089 00090 *yval = 0.0; 00091 00092 for ( i = 0; i <= n; i++ ) 00093 *yval = *yval + ycon[i] * bval[i]; 00094 00095 *zval = 0.0; 00096 00097 for ( i = 0; i <= n; i++ ) 00098 *zval = *zval + zcon[i] * bval[i]; 00099 00100 delete [] bval; 00101 } 00102 00103 } 00104