bezier.cpp File Reference


Detailed Description

Author:
unknown_author
Date:
2003-11-19
Version:
Id
bezier.cpp 8459 2010-03-17 22:02:19Z behrisch

Definition in file bezier.cpp.

#include <config.h>
#include <math.h>
#include <iostream>

Go to the source code of this file.

Functions

SUMOReal Basis (int n, int i, SUMOReal t)
void bezier (int npts, SUMOReal b[], int cpts, SUMOReal p[])
SUMOReal factrl (int n)
SUMOReal Ni (int n, int i)


Function Documentation

SUMOReal Basis ( int  n,
int  i,
SUMOReal  t 
)

Definition at line 90 of file bezier.cpp.

References Ni(), and SUMOReal.

Referenced by bezier().

00090                                        {
00091     SUMOReal basis;
00092     SUMOReal ti; /* this is t^i */
00093     SUMOReal tni; /* this is (1 - t)^i */
00094 
00095     /* handle the special cases to avoid domain problem with pow */
00096 
00097     if (t==0. && i == 0) ti=1.0;
00098     else ti = pow(t,i);
00099     if (n==i && t==1.) tni=1.0;
00100     else tni = pow((1-t),(n-i));
00101     basis = Ni(n,i)*ti*tni; /* calculate Bernstein basis function */
00102     return basis;
00103 }

void bezier ( int  npts,
SUMOReal  b[],
int  cpts,
SUMOReal  p[] 
)

Definition at line 107 of file bezier.cpp.

References Basis(), factrl(), Ni(), and SUMOReal.

Referenced by NBNode::computeInternalLaneShape().

00107                                                        {
00108     int i;
00109     int j;
00110     int i1;
00111     int icount;
00112     int jcount;
00113 
00114     SUMOReal step;
00115     SUMOReal t;
00116 
00117     SUMOReal factrl(int);
00118     SUMOReal Ni(int,int);
00119     SUMOReal Basis(int,int,SUMOReal);
00120 
00121     /*    calculate the points on the Bezier curve */
00122 
00123     icount = 0;
00124     t = 0;
00125     step = (SUMOReal) 1.0/(cpts -1);
00126 
00127     for (i1 = 1; i1<=cpts; i1++) { /* main loop */
00128 
00129         if ((1.0 - t) < 5e-6) t = 1.0;
00130 
00131         for (j = 1; j <= 3; j++) { /* generate a point on the curve */
00132             jcount = j;
00133             p[icount+j] = 0.;
00134             for (i = 1; i <= npts; i++) { /* Do x,y,z components */
00135                 p[icount + j] = p[icount + j] + Basis(npts-1,i-1,t)*b[jcount];
00136                 jcount = jcount + 3;
00137             }
00138         }
00139 
00140         icount = icount + 3;
00141         t = t + step;
00142     }
00143 }

SUMOReal factrl ( int  n  ) 

Definition at line 58 of file bezier.cpp.

References SUMOReal.

Referenced by bezier(), and Ni().

00058                        {
00059     static int ntop=6;
00060     static SUMOReal a[33]= {
00061         1.0,1.0,2.0,6.0,24.0,120.0,720.0
00062     }
00063     ; /* fill in the first few values */
00064     int j1;
00065 
00066     if (n < 0) {
00067         throw 1;
00068     } //cout << "\nNegative factorial in routine FACTRL\n" ;
00069     if (n > 32) {
00070         throw 1;
00071     } //cout << "\nFactorial value too large in routine FACTRL\n";
00072 
00073     while (ntop < n) { /* use the precalulated value for n = 0....6 */
00074         j1 = ntop++;
00075         a[n]=a[j1]*ntop;
00076     }
00077     return a[n]; /* returns the value n! as a SUMORealing point number */
00078 }

SUMOReal Ni ( int  n,
int  i 
)

Definition at line 82 of file bezier.cpp.

References factrl(), and SUMOReal.

Referenced by Basis(), and bezier().

00082                          {
00083     SUMOReal ni;
00084     ni = factrl(n)/(factrl(i)*factrl(n-i));
00085     return ni;
00086 }


Generated on Wed May 5 00:06:37 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6