[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
2.2.3 Curvilinear coordinates
Now let use curvilinear coordinates. In difference from other systems of plot creation, MathGL uses textual formulas for connection of the old (data) and new (output) coordinates. This allows one to plot in arbitrary coordinates. The following code plots the line y=0, z=0 in Cartesian, polar, parabolic and spiral coordinates:
int sample(mglGraph *gr, void *) { mglData x(50),y(50),z(50); y.Fill(0.5,0.5); x.Fill(-1,1); // creates data arrays gr->Axis(mglPoint(-1,-1,-1),mglPoint(1,1,1),mglPoint(-1,1,-1)); gr->dz = 0.5; // sets tick step to 0.5 gr->SubPlot(2,2,0); gr->Rotate(60,40); gr->Plot(x,y,z,"r2"); gr->Axis(); gr->Grid(); gr->Puts(mglPoint(0,1.3,1),"Cartesian"); gr->SubPlot(2,2,1); gr->SetFunc("y*sin(pi*x)","y*cos(pi*x)",0); gr->Rotate(60,40); gr->Plot(x,y,z,"r2"); gr->Axis(); gr->Grid(); gr->Puts(mglPoint(0,1.3,1),"Cylindrical"); gr->SubPlot(2,2,2); gr->Rotate(60,40); gr->SetFunc("2*y*x","y*y - x*x",0); gr->Plot(x,y,z,"r2"); gr->Axis(); gr->Grid(); gr->Puts(mglPoint(0,1.3,1),"Parabolic"); gr->SubPlot(2,2,3); gr->Rotate(60,40); gr->SetFunc("y*sin(pi*x)","y*cos(pi*x)","x+z"); gr->Plot(x,y,z,"r2"); gr->Axis(); gr->Grid(); gr->Puts(mglPoint(0,1.3,1),"Spiral"); return 0; }
Example of curvilinear coordinates