Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 <iostream>
- #include <fstream>
- #include <math.h>
- #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 << " " <<cx << " "<< cy << endl;
- //plot << r << " " << sin(theta) << endl;
- }
- plot.close();
- gp << "unset polar\n";
- gp << "plot \"gear.dat\" using 2:3 with lines\n";
- // gp << "plot \"gear.dat\" using 5:6 with lines\n";
- plot.close();
- }
- int main(int argc, char **argv){
- //init();
- cout << "Enter Number of teeth: ";
- double k = 5;
- cin >> k;
- gear(k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement