Ejemplo n.º 1
0
main()
{
    ginit(500, 500, WHITE);
    GRAPH g;
    g.window(0, -N, 2 * N, N);
    g.line(0, 0, 2 * N, 0);
    g.line(0, N, 0, -N);
    double x, v, f, h, t, tend;
    int step;
    
    x = 1.0;
    v = 0.0;
    f = 0;
    tend = 100;
    h = 0.1;
    
    step = (int)(tend / h);
    
    for(int i = 0; i < step; i++)
    {
        euler(x, v, f, h);
        g.pset(t, x);
        t += h;
    }
    gend();
}
Ejemplo n.º 2
0
main()
{
   int i, j;
   double t, p, x, y, z, r, R, N;
   ginit(500, 500, WHITE);
   GRAPH g;
   g.window(-PI, -PI, PI, PI);
   g.line(-PI, 0, PI, 0);  // x
   g.line(0, PI, 0, -PI);  // y
   g.setcolor(BLACK);
   r = 1.0;
   R = 2.0;
   i = 0;
   while(i < NUMBER)
   {
       t = i * (PI / (NUMBER / 2));
       j = 0;
       while(j < NUMBER)
       {
           p = j * (PI / (NUMBER / 2));
           
           x = R * cos(t) + r * cos(p) * cos(t); //External reference Wikipedia
           y = R * sin(t) + r * cos(p) * sin(t);
           z = r * sin(p);
           
           g.pset(x, y);
           j = j + 1;
       }
       i = i + 1;
   }
   gend();
}