Files Classes Functions Hierarchy
00001 #ifndef SPRING1_H 00002 #define SPRING1_H 00003 00004 #include <cassert> 00005 #include <cmath> 00006 using namespace std; 00007 00008 #include <GL/glut.h> 00009 00010 #include <graphmisc.h> 00011 #include <nintegration.h> 00012 #include <spring.h> 00013 #include <typedefs.h> 00014 00015 00019 class fspring1 00020 { 00021 public: 00022 00023 double kval; 00024 double * x; 00025 00026 void operator () 00027 ( 00028 double & ddx, 00029 doublec & dx, 00030 doublec & t 00031 ) const 00032 { 00033 ddx = -kval*(*x); 00034 } 00035 00036 }; 00037 00038 class fcubicspring1 00039 { 00040 public: 00041 00042 double kval; 00043 double * x; 00044 00046 double A; 00047 double omega; 00048 00049 fcubicspring1() 00050 : A(7.5), omega(1.0) {} 00051 00052 void operator () 00053 ( 00054 double & ddx, 00055 doublec & dx, 00056 doublec & t 00057 ) const 00058 { 00059 double xtmp(*x); 00060 ddx = A*cos(omega*t)-xtmp*xtmp*xtmp-kval*dx; 00061 } 00062 00063 }; 00064 00065 00066 00067 00068 template< typename F > 00069 class spring1 00070 { 00071 public: 00072 00073 DEsys< double, 2, 1 > de; 00074 RK< double, F > fi; 00075 00076 gspring spr; 00077 00078 bool drawenabled; 00079 00080 uint sample; 00081 00082 double lennatural; 00083 00084 spring1() {} 00085 00086 void init 00087 ( 00088 uintc sample_, 00089 doublec h, 00090 doublec t0, 00091 doublec x00, 00092 doublec x10, 00093 doublec kval=0.1, 00094 doublec len=1.0, 00095 doublec radius=0.2 00096 ); 00097 00098 void idle(); 00099 00100 void draw(); 00101 00102 }; 00103 00104 00105 00106 // ------------------------------------------------------------ 00107 // Implementation 00108 00109 00110 template< typename F > 00111 void spring1<F>::draw() 00112 { 00113 if (drawenabled) 00114 { 00115 glPushMatrix(); 00116 00117 spr.draw(); 00118 00119 glPopMatrix(); 00120 } 00121 } 00122 00123 template< typename F > 00124 void spring1<F>::idle() 00125 { 00126 de(); 00127 00128 static uint counter; 00129 00130 ++counter; 00131 if ((counter % sample)==0) 00132 { 00133 spr.h.len = lennatural+de.y[0][0]; 00134 00135 glutPostRedisplay(); 00136 counter=0; 00137 } 00138 } 00139 00140 00141 template< typename F > 00142 void spring1<F>::init 00143 ( 00144 uintc sample_, 00145 doublec h, 00146 doublec t0, 00147 doublec x00, 00148 doublec x10, 00149 doublec kval, 00150 doublec len, 00151 doublec radius 00152 ) 00153 { 00154 de.h[0]=h; 00155 00156 de.xval = t0; 00157 de.yi[0] = x00; 00158 de.yi[1] = x10; 00159 00160 fi.Dy.kval = kval; 00161 fi.Dy.x = & (de.y[0][0]); 00162 00163 de.fi[0] = & fi; 00164 00165 lennatural = len; 00166 00167 spr = gspring 00168 ( 00169 helix(len+x00,10,0.2,200, 0.2,0.8,0.17), 00170 mysphere 00171 ( 00172 radius, 00173 0.1,0.6,0.77, 00174 0.0,0.0,0.0 00175 ) 00176 ); 00177 00178 sample=sample_; 00179 00180 drawenabled=true; 00181 } 00182 00183 00184 00185 #endif 00186
1.5.8