void save(mglGraph *gr,const char *name,const char *suf);\r
void test(mglGraph *gr)\r
{\r
- gr->SubPlot(2,2,0,""); gr->Title("Line, Curve, Rhomb, Ellipse");\r
- gr->Line(mglPoint(-1,-1),mglPoint(-0.5,1),"qAI");\r
- gr->Curve(mglPoint(-0.6,-1),mglPoint(1,1),mglPoint(0,1),mglPoint(1,1),"rA");\r
- gr->Rhomb(mglPoint(0,0.4),mglPoint(1,0.9),0.2,"b#");\r
- gr->Rhomb(mglPoint(0,0),mglPoint(1,0.4),0.2,"cg@");\r
- gr->Ellipse(mglPoint(0,-0.5),mglPoint(1,-0.1),0.2,"u#");\r
- gr->Ellipse(mglPoint(0,-1),mglPoint(1,-0.6),0.2,"m@");\r
- gr->Mark(mglPoint(0,-0.5),"*"); gr->Mark(mglPoint(1,-0.1),"*");\r
- \r
- gr->Light(true);\r
- gr->SubPlot(2,2,1); gr->Title("Face[xyz]"); gr->Rotate(50,60); gr->Box();\r
- gr->FaceX(mglPoint(1,0,-1),1,1,"r");\r
- gr->FaceY(mglPoint(-1,-1,-1),1,1,"g");\r
- gr->FaceZ(mglPoint(1,-1,-1),-1,1,"b");\r
- gr->Face(mglPoint(-1,-1,1),mglPoint(-1,1,1),mglPoint(1,-1,0),mglPoint(1,1,1),"m");\r
- \r
- gr->SubPlot(2,2,3,""); gr->Title("Cone");\r
- gr->Cone(mglPoint(-0.7,-0.3),mglPoint(-0.7,0.7,0.5),0.2,0.1,"b");\r
- gr->Puts(mglPoint(-0.7,-0.7),"no edges\n(default)");\r
- gr->Cone(mglPoint(0,-0.3),mglPoint(0,0.7,0.5),0.2,0.1,"g@");\r
- gr->Puts(mglPoint(0,-0.7),"with edges\n('\\@' style)");\r
- gr->Cone(mglPoint(0.7,-0.3),mglPoint(0.7,0.7,0.5),0.2,0,"ry");\r
- gr->Puts(mglPoint(0.7,-0.7),"'arrow' with\ngradient");\r
+ float a=0.1,b=0.4,c=0.5;\r
+ gr->Line(mglPoint(a,1),mglPoint(b,1),"k-A"); gr->Puts(mglPoint(c,1),"Style 'A' or 'A\\_'",":rL");\r
+ gr->Line(mglPoint(a,0.8),mglPoint(b,0.8),"k-V"); gr->Puts(mglPoint(c,0.8),"Style 'V' or 'V\\_'",":rL");\r
+ gr->Line(mglPoint(a,0.6),mglPoint(b,0.6),"k-K"); gr->Puts(mglPoint(c,0.6),"Style 'K' or 'K\\_'",":rL");\r
+ gr->Line(mglPoint(a,0.4),mglPoint(b,0.4),"k-I"); gr->Puts(mglPoint(c,0.4),"Style 'I' or 'I\\_'",":rL");\r
+ gr->Line(mglPoint(a,0.2),mglPoint(b,0.2),"k-D"); gr->Puts(mglPoint(c,0.2),"Style 'D' or 'D\\_'",":rL");\r
+ gr->Line(mglPoint(a,0),mglPoint(b,0),"k-S"); gr->Puts(mglPoint(c,0),"Style 'S' or 'S\\_'",":rL");\r
+ gr->Line(mglPoint(a,-0.2),mglPoint(b,-0.2),"k-O"); gr->Puts(mglPoint(c,-0.2),"Style 'O' or 'O\\_'",":rL");\r
+ gr->Line(mglPoint(a,-0.4),mglPoint(b,-0.4),"k-T"); gr->Puts(mglPoint(c,-0.4),"Style 'T' or 'T\\_'",":rL");\r
+ gr->Line(mglPoint(a,-0.6),mglPoint(b,-0.6),"k-_"); gr->Puts(mglPoint(c,-0.6),"Style '\\_' or none",":rL");\r
+ gr->Line(mglPoint(a,-0.8),mglPoint(b,-0.8),"k-AS"); gr->Puts(mglPoint(c,-0.8),"Style 'AS'",":rL");\r
+ gr->Line(mglPoint(a,-1),mglPoint(b,-1),"k-_A"); gr->Puts(mglPoint(c,-1),"Style '\\_A'",":rL");\r
\r
- gr->SubPlot(2,2,2,""); gr->Title("Sphere and Drop");\r
- gr->Alpha(false);\r
- gr->Puts(mglPoint(-0.9,-0.7),"sh=0");\r
- gr->Drop(mglPoint(-0.9,0),mglPoint(0,1),0.5,"r",0);\r
- gr->Puts(mglPoint(-0.3,-0.7),"sh=0.33");\r
- gr->Drop(mglPoint(-0.3,0),mglPoint(0,1),0.5,"r",0.33);\r
- gr->Puts(mglPoint(0.3,-0.7),"sh=0.67");\r
- gr->Drop(mglPoint(0.3,0),mglPoint(0,1),0.5,"r",0.67);\r
- gr->Puts(mglPoint(0.9,-0.7),"sh=1");\r
- gr->Drop(mglPoint(0.9,0),mglPoint(0,1),0.5,"r",1);\r
- gr->Ball(mglPoint(-0.9,0,1),'k');\r
- gr->Ball(mglPoint(-0.3,0,1),'k');\r
- gr->Ball(mglPoint(0.3,0,1),'k');\r
- gr->Ball(mglPoint(0.9,0,1),'k');\r
- gr->Line(mglPoint(-0.9,0,1),mglPoint(0.9,0,1),"b");\r
+ a=-1; b=-0.7; c=-0.6;\r
+ gr->Line(mglPoint(a,1),mglPoint(b,1),"kAA"); gr->Puts(mglPoint(c,1),"Style 'AA'",":rL");\r
+ gr->Line(mglPoint(a,0.8),mglPoint(b,0.8),"kVV"); gr->Puts(mglPoint(c,0.8),"Style 'VV'",":rL");\r
+ gr->Line(mglPoint(a,0.6),mglPoint(b,0.6),"kKK"); gr->Puts(mglPoint(c,0.6),"Style 'KK'",":rL");\r
+ gr->Line(mglPoint(a,0.4),mglPoint(b,0.4),"kII"); gr->Puts(mglPoint(c,0.4),"Style 'II'",":rL");\r
+ gr->Line(mglPoint(a,0.2),mglPoint(b,0.2),"kDD"); gr->Puts(mglPoint(c,0.2),"Style 'DD'",":rL");\r
+ gr->Line(mglPoint(a,0),mglPoint(b,0),"kSS"); gr->Puts(mglPoint(c,0),"Style 'SS'",":rL");\r
+ gr->Line(mglPoint(a,-0.2),mglPoint(b,-0.2),"kOO"); gr->Puts(mglPoint(c,-0.2),"Style 'OO'",":rL");\r
+ gr->Line(mglPoint(a,-0.4),mglPoint(b,-0.4),"kTT"); gr->Puts(mglPoint(c,-0.4),"Style 'TT'",":rL");\r
+ gr->Line(mglPoint(a,-0.6),mglPoint(b,-0.6),"k-__"); gr->Puts(mglPoint(c,-0.6),"Style '\\_\\_'",":rL");\r
+ gr->Line(mglPoint(a,-0.8),mglPoint(b,-0.8),"k-VA"); gr->Puts(mglPoint(c,-0.8),"Style 'VA'",":rL");\r
+ gr->Line(mglPoint(a,-1),mglPoint(b,-1),"k-AV"); gr->Puts(mglPoint(c,-1),"Style 'AV'",":rL");\r
return;\r
\r
mglParse par;\r
/// Write the frame in file using OFF format\r
inline void WriteOFF(const char *fname,const char *descr="", bool colored=false)\r
{ mgl_write_off(gr, fname, descr,colored); }\r
- /// Write the frame in file using X3D format\r
- inline void WriteX3D(const char *fname,const char *descr="")\r
- { mgl_write_x3d(gr, fname, descr); }\r
+// /// Write the frame in file using X3D format\r
+// inline void WriteX3D(const char *fname,const char *descr="")\r
+// { mgl_write_x3d(gr, fname, descr); }\r
/// Write the frame in file using IDTF format\r
inline void WriteIDTF(const char *fname,const char *descr="")\r
{ mgl_write_idtf(gr, fname, descr); }\r
q3.xx=q3.x=p1.x+lx; q3.yy=q3.y=p1.y+ly; k3=Pnt.size(); MGL_PUSH(Pnt,q3,mutexPnt);\r
trig_plot(k1,k2,k3); break;\r
case 'A':\r
- q1.xx=q1.x=p1.x; q1.yy=q1.y=p1.y; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
+// q1.xx=q1.x=p1.x; q1.yy=q1.y=p1.y; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
q2.xx=q2.x=p1.x-kx-2*lx; q2.yy=q2.y=p1.y-ky-2*ly; k2=Pnt.size(); MGL_PUSH(Pnt,q2,mutexPnt);\r
q3.xx=q3.x=p1.x-1.5*lx; q3.yy=q3.y=p1.y-1.5*ly; k3=Pnt.size(); MGL_PUSH(Pnt,q3,mutexPnt);\r
q4.xx=q4.x=p1.x+kx-2*lx; q4.yy=q4.y=p1.y+ky-2*ly; k4=Pnt.size(); MGL_PUSH(Pnt,q4,mutexPnt);\r
- quad_plot(k1,k2,k4,k3); break;\r
+ trig_plot(n1,k2,k3); trig_plot(n1,k4,k3); break;\r
case 'K':\r
- q1.xx=q1.x=p1.x; q1.yy=q1.y=p1.y; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
+// q1.xx=q1.x=p1.x; q1.yy=q1.y=p1.y; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
q2.xx=q2.x=p1.x-kx-2*lx; q2.yy=q2.y=p1.y-ky-2*ly; k2=Pnt.size(); MGL_PUSH(Pnt,q2,mutexPnt);\r
q3.xx=q3.x=p1.x-1.5*lx; q3.yy=q3.y=p1.y-1.5*ly; k3=Pnt.size(); MGL_PUSH(Pnt,q3,mutexPnt);\r
q4.xx=q4.x=p1.x+kx-2*lx; q4.yy=q4.y=p1.y+ky-2*ly; k4=Pnt.size(); MGL_PUSH(Pnt,q4,mutexPnt);\r
- quad_plot(k1,k2,k4,k3);\r
+ trig_plot(n1,k2,k3); trig_plot(n1,k4,k3);\r
q1.xx=q1.x=p1.x+kx; q1.yy=q1.y=p1.y+ky; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
q2.xx=q2.x=p1.x-kx; q2.yy=q2.y=p1.y-ky; k2=Pnt.size(); MGL_PUSH(Pnt,q2,mutexPnt);\r
line_plot(k1,k2); break;\r
case 'V':\r
- q1.xx=q1.x=p1.x; q1.yy=q1.y=p1.y; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
+// q1.xx=q1.x=p1.x; q1.yy=q1.y=p1.y; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
q2.xx=q2.x=p1.x-kx+2*lx; q2.yy=q2.y=p1.y-ky+2*ly; k2=Pnt.size(); MGL_PUSH(Pnt,q2,mutexPnt);\r
q3.xx=q3.x=p1.x+1.5*lx; q3.yy=q3.y=p1.y+1.5*ly; k3=Pnt.size(); MGL_PUSH(Pnt,q3,mutexPnt);\r
q4.xx=q4.x=p1.x+kx+2*lx; q4.yy=q4.y=p1.y+ky+2*ly; k4=Pnt.size(); MGL_PUSH(Pnt,q4,mutexPnt);\r
- quad_plot(k1,k2,k4,k3); break;\r
+ trig_plot(n1,k2,k3); trig_plot(n1,k4,k3); break;\r
case 'O':\r
{\r
q1.xx=q1.x=p1.x; q1.yy=q1.y=p1.y; k1=Pnt.size(); MGL_PUSH(Pnt,q1,mutexPnt);\r
Exports current frame to OFF file using vector representation (see @url{http://people.sc.fsu.edu/~jburkardt/data/off/off.html, OFF format} for details). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter @var{fname} specifies the file name, @var{descr} adds description to file (default is file name).
@end deftypefn
-@deftypefn {Method on @code{mglGraph}} @code{void} WriteX3D (@code{const char *}fname, @code{const char *}descr=@code{""})
-@deftypefnx {C function} @code{void} mgl_write_x3d (@code{HMGL} gr, @code{const char *}fname, @code{const char *}descr)
-Exports current frame to OBJ/MTL file using vector representation (see @url{http://en.wikipedia.org/wiki/X3d, X3D format} for details). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter @var{fname} specifies the file name, @var{descr} adds description to file (default is file name).
-@end deftypefn
+@c @deftypefn {Method on @code{mglGraph}} @code{void} WriteX3D (@code{const char *}fname, @code{const char *}descr=@code{""})
+@c @deftypefnx {C function} @code{void} mgl_write_x3d (@code{HMGL} gr, @code{const char *}fname, @code{const char *}descr)
+@c Exports current frame to OBJ/MTL file using vector representation (see @url{http://en.wikipedia.org/wiki/X3d, X3D format} for details). Note, the output file may be too large for graphic of large data array (especially for surfaces). It is better to use bitmap format (for example PNG or JPEG). However, program has no internal limitations for size of output file. Parameter @var{fname} specifies the file name, @var{descr} adds description to file (default is file name).
+@c @end deftypefn
@deftypefn {Method on @code{mglGraph}} @code{void} WriteIDTF (@code{const char *}fname, @code{const char *}descr=@code{""})
This chapter contain information about basic and advanced MathGL, hints and samples for all types of graphics. I recommend you read first 2 sections one after another and at least look on @ref{Hints} section. Also I recommend you to look at @ref{General concepts} and @ref{FAQ}.
+Note, that MathGL v.2.* have only 2 end-user interfaces: one for C/Fortran and similar languages which don't support classes, another one for C++/Python/Octave and similar languages which support classes. So, most of samples placed in this chapter can be run as is (after minor changes due to different syntaxes for different languages). For example, the C++ code
+@verbatim
+#include <mgl/mgl.h>
+int main()
+{
+ mglGraph gr;
+ gr.FPlot("sin(pi*x)");
+ gr.WriteFrame("test.png");
+}
+@end verbatim
+in Python will be as
+@verbatim
+from mathgl import *
+gr = mglGraph();
+gr.FPlot("sin(pi*x)");
+gr.WriteFrame("test.png");
+@end verbatim
+in Octave will be as (you need first install MathGL package by command @code{octave:1> pkg install /usr/share/mathgl/octave/mathgl.tar.gz} from @code{sudo octave})
+@verbatim
+gr = mglGraph();
+gr.FPlot("sin(pi*x)");
+gr.WriteFrame("test.png");
+@end verbatim
+in C will be as
+@verbatim
+#include <mgl/mgl_cf.h>
+int main()
+{
+ HMGL gr = mgl_create_graph(600,400);
+ mgl_fplot(gr,"sin(pi*x)","","");
+ mgl_write_frame(gr,"test.png","");
+ mgl_delete_graph(gr);
+}
+@end verbatim
+in Fortran will be as
+@verbatim
+integer gr, mgl_create_graph
+gr = mgl_create_graph(600,400);
+call mgl_fplot(gr,'sin(pi*x)','','');
+call mgl_write_frame(gr,'test.png','');
+call mgl_delete_graph(gr);
+@end verbatim
+and so on.
+
+
+
@menu
* Basic usage::
* Advanced usage::
}
@end verbatim
+Previous sample can be run in C++ only since it use C++ class mglDraw. However similar idea can be used even in Fortran or SWIG-based (Python/Octave/...) if one use FLTK window. Such limitation come from the Qt requirement to be run in the primary thread only. The sample code will be:
+@verbatim
+int main(int argc,char **argv)
+{
+ mglWindow gr("test"); // create window
+ gr.RunThr(); // run event loop in separate thread
+ for(int i=0;i<10;i++) // do calculation
+ {
+ sleep(1); // which can be very long
+ pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1);
+ gr.Clf(); // make new drawing
+ gr.Line(mglPoint(),pnt,"Ar2");
+ char str[10] = "i=0"; str[3] = '0'+i;
+ gr.Puts(mglPoint(),"");
+ gr.Update(); // update window when you need it
+ }
+ return 0; // finish calculations and close the window
+}
+@end verbatim
+
-Pictures with animation can be saved in file(s) as well. You can: export in animated GIF, or save each frame in separate file (usually JPEG) and convert these files into the movie (for example, by help of ImageMagic). Let me show both methods.
+Pictures with @strong{animation can be saved in file(s)} as well. You can: export in animated GIF, or save each frame in separate file (usually JPEG) and convert these files into the movie (for example, by help of ImageMagic). Let me show both methods.
The simplest methods is making animated GIF. There are 3 steps: (1) open GIF file by @code{StartGIF()} function; (2) create the frames by calling @code{NewFrame()} before and @code{EndFrame()} after plotting; (3) close GIF by @code{CloseGIF()} function. So the simplest code for ``running'' sinusoid will look like this:
@verbatim
In fact, I created the functions for drawing of all the types of scientific plots that I know. The list of plots is growing; if you need some special type of a plot then please email me @email{mathgl.abalakin@@gmail.com, e-mail} and it will appear in the new version.
-I tried to make plots as nice looking as possible: e.g., a surface can be transparent and highlighted by several (up to 10) light sources. Most of the drawing functions have 2 variants: simple one for the fast plotting of data, complex one for specifying of the exact position of the plot (including parametric representation). Resulting image can be saved in bitmap PNG, JPEG, TGA, BMP format, or in vector EPS, SVG or TeX format, or in 3D formats OBJ, OFF, STL or X3D, or in IDTF format which can be converted into U3D.
+I tried to make plots as nice looking as possible: e.g., a surface can be transparent and highlighted by several (up to 10) light sources. Most of the drawing functions have 2 variants: simple one for the fast plotting of data, complex one for specifying of the exact position of the plot (including parametric representation). Resulting image can be saved in bitmap PNG, JPEG, TGA, BMP format, or in vector EPS, SVG or TeX format, or in 3D formats OBJ, OFF, STL, or in IDTF format which can be converted into U3D.
All texts are drawn by vector fonts, which allows for high scalability and portability. Texts may contain commands for: some of the TeX-like symbols, changing index (upper or lower indexes) and the style of font inside the text string (@pxref{Font styles}). Texts of ticks are rotated with axis rotation. It is possible to create a legend of plot and put text in an arbitrary position on the plot. Arbitrary text encoding (by the help of function @code{setlocale()}) and UTF-16 encoding are supported.
@item
Improve MGL scripts. Add 'ask' command and allow string concatenation from different lines.
@item
-Export to LaTeX and to 3D formats (OBJ, OFF, STL, X3D).
+Export to LaTeX and to 3D formats (OBJ, OFF, STL).
@item
Add pipes support in utilities (@code{mglconv, mglview}).
@end itemize
@item
Improve MGL scripts. Add 'ask' command and allow string concatenation from different lines.
@item
-Export to LaTeX and to 3D formats (OBJ, OFF, STL, X3D).
+Export to LaTeX and to 3D formats (OBJ, OFF, STL).
@item
Add pipes support in utilities (@code{mglconv, mglview}).
@end itemize
In fact, I created the functions for drawing of all the types of scientific plots that I know. The list of plots is growing; if you need some special type of a plot then please email me @email{mathgl.abalakin@@gmail.com, e-mail} and it will appear in the new version.
-I tried to make plots as nice looking as possible: e.g., a surface can be transparent and highlighted by several (up to 10) light sources. Most of the drawing functions have 2 variants: simple one for the fast plotting of data, complex one for specifying of the exact position of the plot (including parametric representation). Resulting image can be saved in bitmap PNG, JPEG, TGA, BMP format, or in vector EPS, SVG or TeX format, or in 3D formats OBJ, OFF, STL or X3D, or in IDTF format which can be converted into U3D.
+I tried to make plots as nice looking as possible: e.g., a surface can be transparent and highlighted by several (up to 10) light sources. Most of the drawing functions have 2 variants: simple one for the fast plotting of data, complex one for specifying of the exact position of the plot (including parametric representation). Resulting image can be saved in bitmap PNG, JPEG, TGA, BMP format, or in vector EPS, SVG or TeX format, or in 3D formats OBJ, OFF, STL or in IDTF format which can be converted into U3D.
All texts are drawn by vector fonts, which allows for high scalability and portability. Texts may contain commands for: some of the TeX-like symbols, changing index (upper or lower indexes) and the style of font inside the text string. Texts of ticks are rotated with axis rotation. It is possible to create a legend of plot and put text in an arbitrary position on the plot. Arbitrary text encoding (by the help of function @code{setlocale()}) and UTF-16 encoding are supported.
@deftypefn {Slot on @code{QMathGL}} @code{void} exportOFF (@code{QString} fname=@code{""})
Export current picture to OFF file.
@end deftypefn
-@deftypefn {Slot on @code{QMathGL}} @code{void} exportX3D (@code{QString} fname=@code{""})
-Export current picture to X3D file.
-@end deftypefn
+@c @deftypefn {Slot on @code{QMathGL}} @code{void} exportX3D (@code{QString} fname=@code{""})
+@c Export current picture to X3D file.
+@c @end deftypefn
@deftypefn {Slot on @code{QMathGL}} @code{void} exportIDTF (@code{QString} fname=@code{""})
Export current picture to IDTF file.
1. Add sample for window in python/octave (like pthread) -- Docs
2. Add help about cmake into the "Installation and using" -- after build system will be ready
-3. Export to X3D
-4. Check RunThr()
+4. Check RunThr() in python
============= FOR V.2.1 ========
20. Add mglDataC for complex data -- main diff is reading/saving data
21. MGL testing system ???
+22. Export to X3D
+23. Try libtcc (TinyCC) as alternative to MGL -- in mgllab???
============= UDAV =============