/* * Gear Curve * x = r*cos*theta * y = r*sin*theta * r=a+(1/b)*tanh(b*sin(n*theta)), *where tanhx is the hyperbolic tangent. Plots above show gear curves for a=1, b=10, and n=1 to 12. */ //g++ -Wall -o "%e" "%f" -lboost_iostreams -lboost_system -lboost_filesystem -lSDL -lSDL_image -lSDL_ttf -lSDL_mixer -lGLU -lglut -lXi -lXmu `pkg-config --libs opencv` #include #include #include #include "/usr/include/gnuplot-iostream.h" using namespace std; void init(){ Gnuplot gp; } void gear(double teeth){ Gnuplot gp; ofstream plot; plot.open("gear.dat"); // x = r*cos*theta // y = r*sin*theta // r=a+(1/b)*tanh(b*sin(n*t)) double a =1.5; double b =12; const double pi = 3.14159265359; double r =0; double cR=0; double n = 1;// teeth? n=teeth; double xx=0; double yy = 0; double cx = 0; double cy = 0; for(int t=0; t<=360; t++){ double theta =(t*pi)/180; r=a+(1/b)*tanh(b*sin(n*theta)); xx = r * cos(theta); yy = r * sin(theta); cR=a+(1-b)*tanh(b*sin(0*theta)); cx=cR*cos(theta); cy=cR*sin(theta); plot << r <<" " << xx << " " << yy << " " << cR << " " <> k; gear(k); return 0; }