j0h

gnuplot-iostream

j0h
May 5th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. /*
  2.  *  https://en.wikipedia.org/wiki/Rose_(mathematics)
  3.  *  k == number of petals
  4.     x = cos( k theta ) * cos( theta )
  5.     y = cos( k theta ) * sin( theta )
  6.     *
  7.     * build commands:
  8.     * g++ -Wall -o "%e" "%f" -lboost_iostreams -lboost_system -lboost_filesystem `pkg-config --cflags --libs sdl2`
  9.  */
  10. #include <iostream>
  11. #include <fstream>
  12. #include <math.h>
  13. #include "/usr/include/gnuplot-iostream.h"
  14.  
  15. using namespace std ;
  16. int main(){
  17.    
  18.     Gnuplot gp;
  19.     ofstream plot;
  20.     plot.open("rose.dat");
  21.     const double pi = 3.14159265359;
  22.     double  theta = 0;
  23.     int    k = 8; //N of Petals
  24.     double r,r1,r2 = 0;
  25.      
  26.     double xx = 0;
  27.     double yy = 0;
  28.  
  29.  
  30. for(int t=0; t<=20; t++){
  31.     theta =(t*pi)/180;
  32.     r = cos(k*theta);
  33.      xx = cos((k)*theta)*cos(theta);
  34.      //yy = sin(theta)*sin(r);
  35.      //yy = cos(k*theta)*sin(r);
  36.      //yy = cos(k*theta)*sin(theta); theta =(t*pi)/180;
  37.     r1 =12*cos(r);
  38.     r2 =-12*cos(k*theta);
  39.     yy = cos(k*theta)*sin(theta);
  40.      
  41.  
  42. //cout << r << " " << xx << " " << yy << endl;     
  43. plot << r << " "<< r1 << " "<< r2 << " " << xx << " " << yy << endl;   
  44.     }
  45. plot.close();
  46. //gp<<"gnuplot\n";
  47. gp << "set polar\n";
  48.     //gp << "plot \"rose.dat\" using 1 with lines\n";
  49.     //gp << "plot \"rose.dat\" using 2 with lines\n";
  50.     gp << "plot \"rose.dat\" using 3 with lines\n";
  51.     //gp << "";
  52.  
  53. return 0;
  54. }
Add Comment
Please, Sign In to add comment