Re: [GD-DEVEL] Re: plotting data c++
| From: | Pierre Joye | Date: | Thu, 31 Jan 2008 16:42:59 +0000 |
| Subject: | Re: [GD-DEVEL] Re: plotting data c++ | ||
| References: | 1 2 3 4 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-346@lists.php.net to get a copy of this message | ||
On Jan 31, 2008 4:05 PM, Patolfo <patolfo@gmail.com> wrote:
> Using gnuplot is what i am doing right now, but if a share my program as
> it has to be, the the other person must have gnuplot, that's why i tried
> to port perl to c, and compile it, i do have many ways of plotting data,
> excel, matlab, maple, cosmos, gnuplot, origin, but it is necesary to
> have them installed on the other machines, besides, the program is
> interactive, so, every time you change the input variables, you have to
> replot, that means to have to use two program at a time, i want it to be
> just one :)
>
> Yeah sound selfish, excuse me for trying to make a fanvy program by the way.
>
> The code is below:
>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <math.h>
> >
> > /* What are we doing here
> > We are adding harmonics or terms: n in this case, of a sine curve,
> > not a continuous sine curve but a sampled one, this sine curve is
> > depicted by x and sin(x) where x can be seen as the abscissa
> > while sin(x) the ordinate in a cartesian coordinated system,
> > the resulting square wave is seen when plotting x vs y
> > */
> > int main()
> > {
> > FILE *destino = fopen( "destino.txt", "w" );
> >
> > int n,h;
> > float x,pi=3.14159265358979,y=0;
> > printf("Number of terms: ");
> > scanf("%d", &n); /* Read the number of terms -harmonics- for
> > the approximation */
> > /* Definition of the curve points, i.e., sampling points that
> > define the curve */
> > for(x = 0;x <= 2*pi;x+=pi/256)
> > {
> > y=0;
> > // Harmonic number, 1 is the fundamental, 2,4,6... the harmonics
> > for(h = 1;h <= n;h+=2)
> > {
> > // Summation of a sine curve harmonics, point by point
> > y+=sin(h*x)/h;
> > };
> > // Yields the points that define and square wave
> > printf("%-2.8g \n", y);
> > fprintf( destino, "%-2.8g %-2.8g \n", x,y);
> > }
> > fclose(destino);
> > return 0;
> > }
> It gives a file "destino.txt" with a variable number of data pairs
> dpening on the number of samples used, and it is always between 0 and 1.
>
> This is the routine for the dtaa generation, for the gui i am working on
> it, just making fancy with menus and the like, the problem of the plot
> or graph it self is where i am stalled.
And what you want is to output a curve in a 2D chart? a simple
plotting chart? It should not be that hard to draw it with gd only.
By the way, on which platform do you work?
Cheers,
--
Pierre
http://blog.thepimp.net | http://www.libgd.org