/* * https://en.wikipedia.org/wiki/Rose_(mathematics) * k == number of petals x = cos( k theta ) * cos( theta ) y = cos( k theta ) * sin( theta ) * * build commands: * g++ -Wall -o "%e" "%f" -lboost_iostreams -lboost_system -lboost_filesystem `pkg-config --cflags --libs sdl2` */ #include #include #include #include "/usr/include/gnuplot-iostream.h" using namespace std ; int main(){ Gnuplot gp; ofstream plot; plot.open("rose.dat"); const double pi = 3.14159265359; double theta = 0; int k = 8; //N of Petals double r,r1,r2 = 0; double xx = 0; double yy = 0; for(int t=0; t<=20; t++){ theta =(t*pi)/180; r = cos(k*theta); xx = cos((k)*theta)*cos(theta); //yy = sin(theta)*sin(r); //yy = cos(k*theta)*sin(r); //yy = cos(k*theta)*sin(theta); theta =(t*pi)/180; r1 =12*cos(r); r2 =-12*cos(k*theta); yy = cos(k*theta)*sin(theta); //cout << r << " " << xx << " " << yy << endl; plot << r << " "<< r1 << " "<< r2 << " " << xx << " " << yy << endl; } plot.close(); //gp<<"gnuplot\n"; gp << "set polar\n"; //gp << "plot \"rose.dat\" using 1 with lines\n"; //gp << "plot \"rose.dat\" using 2 with lines\n"; gp << "plot \"rose.dat\" using 3 with lines\n"; //gp << ""; return 0; }