[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Draw a ellipse
Hello.
I'm trying to draw the following figure with epix:
|x|^n + |y|^n = 1 for n=2,3,4,5...
Here is the c++ code.
#include "epix.h"
#include <cmath>
using namespace ePiX;
// the function to be plotted
double f(double x){return exp(log(1.0-abs(x*x))/2.0);}
double g(double x){return -exp(log(1.0-abs(x*x))/2.0);}
double h1(double x){return sqrt(1-x*x);}
double h2(double x){return -sqrt(1-x*x);}
main(){
bounding_box(P(-1,-1),P(1,1));
unitlength("1in"); picture(P(1,1));
begin();
plot(f, x_min,x_max,80);
plot(g, x_min,x_max,80);
plot(h1, x_min,x_max,40);
plot(h2, x_min,x_max,40);
end();
}
What I would like to do is to plot f and g, and they should be the same as h1
and h2, but they are not!! Why? It's the same bad result with n=3,4,5...
It's more like a square for n=2 (which should be a circle!)
Is the problem related to accuracy, rounding, resolution?
It works fine with a parametric solution and trig. functions. But what's the
matter with the exp and log version?
I have to use exp and log if I would like to use n=2.5 (something between 2
and 3).
Gunnar.