#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <plplot/plplot.h>
long unsigned int NUM_PTS = 10000;
PLINT XMAX = 2;
PLINT YMAX = 2;
void generateCurve(PLFLT *x, PLFLT *y)
{
int i = 0;
double r, theta=0.f;
float step = 2*PI/NUM_PTS;
float s, c;
while(theta < 2*PI)
{
s = sin(theta); c = cos(theta);
r = sqrt(s * c / (pow(s,4) - pow(c,4)));
x[i] = (PLFLT) (r * cos(theta));
y[i] = (PLFLT) (r * sin(theta));
/*
x[i] = (PLFLT) cos(theta) * sqrt(-1/sin(theta*4)) * modulus(sin(2*theta));
y[i] = (PLFLT) sin(theta) * sqrt(-1/sin(theta*4)) * modulus(sin(2*theta));
*/
theta += (double) step;
i++;
}
}
int main(void)
{
PLFLT *X = NULL, *Y = NULL;
plscolbg(255, 255, 255);
plsdev("wxwidget");
plinit(); // initialize plotting library
plscol0(15, 0, 0, 0);
plcol(15);
plenv(-XMAX, XMAX, -YMAX, YMAX, 1, -2);
plbox( "abcstn", 0, 0, "anbcst", 0, 0);
pllab("X", "Y", "Swastika Curve");
X = (PLFLT*) malloc(NUM_PTS * sizeof(PLFLT*));
Y = (PLFLT*) malloc(NUM_PTS * sizeof(PLFLT*));
if(X == NULL || Y == NULL)
{
perror("Unable to allocate memory!!");
free(X); free(Y); exit(1);
}
generateCurve(X, Y);
plline(NUM_PTS, X, Y);
plend(); // close the plotting library
{ free(X); free(Y); }
return 0;
}