Now Reading
Getting began with C++ MathGL on Home windows and Linux

Getting began with C++ MathGL on Home windows and Linux

2023-03-04 07:35:12

Posted on June 25, 2020 by Paul

On this article, I’ll present you the best way to set up and get began with the C++ interface of MathGL on Linux and Home windows. MathGL is a top quality scientific graphics library.

Within the first two elements of the article I’ll describe the best way to set up the library and the best way to construct a C++ MathGL instance. Within the third a part of the article we’ll use MathGL to create a 2D operate graphic and reserve it as a picture file. As a second instance, we’ll use the FLTK GUI library to point out the identical 2D operate:

MathGL Demo two dimensional wave curve function

This text is cut up in three elements:

I like to recommend that you just learn the set up half to your OS and the half that exhibits the best way to use MathGL to create some graphics.

Set up MathGL on Home windows:

On Home windows, the advisable method to put in MathGL is to make use of the official MathGL binaries. From the above web page, obtain the GPL or LGPL binaries for MinGW 64 bits. After you’ve completed downloading the archive, you possibly can extract it with 7zip.

Subsequent, we’re going to set up the MinGW 64 GCC toolchain that was used to construct the library. On the present time, best method is to obtain Code::Blocks model 20.03. Be certain to obtain the file named codeblocks-20.03mingw-setup.exe.

Begin the Code::Blocks installer and settle for the defaults. As soon as the set up is completed, Code::Blocks will detect the included GCC toolchain.

Subsequent, you have to to manually copy the content material of the MathGL archive to the situation the place Code::Blocks has put in GCC, that is normally C:Program FilesCodeBlocksMinGW.

Copy the content material of the bin folder of MathGL to the the bin folder of MinGW. When requested if you wish to overwrite some recordsdata with the identical names, skip these recordsdata.

Copy the content material of the lib folder of MathGL to the the lib folder of MinGW.

Open the embody folder of MathGL and replica the embody folder mgl2. Contained in the MinGW folder, go to x86_64-w64-mingw32, open the embody folder and paste the mgl2 folder in right here.

Open Code::Blocks and create a brand new challenge, selected Console Software and C++. Selected a reputation for the challenge and a location.

As soon as the C++ console challenge is open, proper click on on the challenge identify (within the left panel) and choose Construct choices. Choose Linker Settings and within the Different linker choices panel add the specified libraries: -lmgl on this case. If you need to have the ability to use the FLTK GUI library, like you will note in our second instance, you have to so as to add -lmgl -lmgl-fltk. Press OK.

In Code::Blocks, you need to use the Construct and Run button (the small wheel with a inexperienced triangle icon) to compile and execute a program.

Subsequent, take away the default C++ generated code from predominant.cpp and go to MathGL usage a part of this text for an instance.

Set up MathGL on Linux:

For Linux, I’ll exemplify the set up half on a Debian primarily based system.

Let’s begin by putting in a C++ toolchain. Open a Terminal and write:

1 sudo apt set up build-essential

Subsequent, set up MathGL with:

See Also

1 sudo apt set up libmgl-dev

Assuming that you just’ve saved your MathGL program in a file named mgl_ex1.cpp, that is how one can construct it:

1 g++ mgl_ex1.cpp -o mgl_ex1 -lmgl

or, in case you are utilizing the FLTK GUI library:

1 g++ mgl_ex1.cpp -o mgl_ex1 -lmgl -lmgl-fltk

As soon as this system is compiled, you possibly can run it as regular on Linux with:

1 ./mgl_ex1

Subsequent, go to the MathGL usage a part of this text for an instance program.

C++ MathGL utilization instance:

Here’s a small C++ MathGL program that may draw a wave curve and save the graphic in a picture file named mgl_example.png:

 1 #embody <mgl2mgl.h>
 2 
 3 int predominant() {
 4     mglGraph gr;
 5     gr.Title("MathGL Demo");
 6     gr.SetOrigin(0, 0);
 7     gr.SetRanges(0, 10, -2.5, 2.5);
 8     gr.FPlot("sin(1.7*2*pi*x) + sin(1.9*2*pi*x)", "r-2");
 9     gr.Axis();
10     gr.Grid();
11     gr.WriteFrame("mgl_example.png");
12 }

The picture will probably be saved the place your program executable is positioned.

Subsequent, we’ll draw the identical curve, however this time utilizing a FLTK window that may allow you to play with the graph: zoom, pan, rotate and different operations:

 1 #embody <mgl2/fltk.h>
 2 
 3 int graph(mglGraph *gr) {
 4     gr->Title("MathGL Demo");
 5     gr->SetOrigin(0, 0);
 6     gr->SetRanges(0, 10, -2.5, 2.5);
 7     gr->FPlot("sin(1.7*2*pi*x) + sin(1.9*2*pi*x)", "r-4");
 8     gr->Axis();
 9     gr->Grid();
10     return 0;
11 }
12 
13 int predominant() {
14     mglFLTK gr(graph, "MathGL demo window title");
15     return gr.Run();
16 }

If you wish to be taught extra concerning the capabilities of MathGL I like to recommend that you just test their examples and the user manual.


Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top