home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff376.lzh / Plotter / src / Berechnungsroutinen.c < prev    next >
Text File  |  1990-10-10  |  8KB  |  332 lines

  1.  /********************************************************************/
  2.  /****                                                            ****/
  3.  /****                                                            ****/
  4.  /****    Program          : BerechnungsRoutinen.c                ****/
  5.  /****                                                            ****/
  6.  /****    Version          :    03.71                             ****/
  7.  /****                                                            ****/
  8.  /****    Erstversion      : 14.08.1988                           ****/
  9.  /****                                                            ****/
  10.  /****    Letzte Änderung  : 05.08.1990                           ****/
  11.  /****                                                            ****/
  12.  /****    Compiliert mit   : siehe MAKEFILE                       ****/
  13.  /****                                                            ****/
  14.  /****    Gelinkt mit      : siehe MAKEFILE                       ****/
  15.  /****                                                            ****/
  16.  /********************************************************************/
  17.  /****                                                            ****/
  18.  /****                                                            ****/
  19.  /****               Copyright by Rüdiger Dreier                  ****/
  20.  /****                                                            ****/
  21.  /****                                                            ****/
  22.  /********************************************************************/
  23.  
  24.  /* Einbinden der Include-Files */
  25.  
  26.  #ifdef DEBUG
  27.  #include "Plotter.h"
  28.  #include <proto/tool.h>
  29.  #endif
  30.  #include <string.h>
  31.  #include <graphics/gfxmacros.h>
  32.  #include <proto/mathieeedoubbas.h>
  33.  #include <proto/mathieeedoubtrans.h>
  34.  #include <graphics/regions.h>
  35.  #include <proto/layers.h>
  36.  #include <stdio.h>
  37.  
  38.  LONG MatheFehler;
  39.  char flagg;
  40.  
  41.  SHORT Genauigkeiten[3]=
  42.   {
  43.    8,4,1
  44.   };
  45.  
  46.  /* Funktion testet, ob ein Fehler aufgetreten ist */
  47.  VOID FehlerAbfrage(VOID)
  48.   {
  49.    /* Abfrage auf Mathe-Fehler */
  50.    if (MatheFehler)
  51.     {
  52.      request("OK","OK",BE_ERROR);
  53.     }
  54.    MatheFehler=0;
  55.   }
  56.  
  57.  
  58.  /* Zeichnet die n-te Ableitung der Funktion nr */
  59.  VOID __asm ZeichneFunktion(register __d0 USHORT nr,
  60.                             register __d1 int Ableitung)
  61.   {
  62.    USHORT ZEICHNEN=TRUE;
  63.    double i,xalt,yalt,y;
  64.    ULONG OldIDCMP;
  65.    SHORT MaxXPos,Pos;
  66.    LONG H;
  67.    
  68.    MaxXPos=(SHORT)(xx-Genauigkeiten[GE]);
  69.    
  70.    SetAPen(RastPort,FARBE1);
  71.    
  72.    /* Berechnet Position der x/y-Achse */
  73.    x0=Add(Mul(Div(Neg(xmn),Sub(xmp,xmn)),Flt(xx-1)),1.0);
  74.    y0= Add(Mul(Div(ymp,Sub(ymp,ymn)),Flt(yy-1)),1.0);
  75.    
  76.    /* Bestimmt Zeichenmaßstab */
  77.    xm=Div(Flt(xx-1),Sub(xmp,xmn));
  78.    ym=Div(Flt(yy-1),Sub(ymp,ymn));
  79.    
  80.    
  81.    OldIDCMP=Window->IDCMPFlags;
  82.    ModifyIDCMP(Window,MOUSEBUTTONS);
  83.    
  84.    if(!KoordinatenKreuz_gezeichnet)Loeschen();
  85.    SetAPen(RastPort,FARBE3);
  86.    flagg=1;    /* ersten Punkt nur setzen     */
  87.    
  88.    StartBlock=Init_Mem(Formeln[nr]);
  89.    MatheFehler=Init_Block(StartBlock);
  90.    MatheFehler|=PreCalc(StartBlock,Konstantenstart);
  91.    if(MatheFehler)
  92.     {
  93.      FehlerAbfrage(); /* Es ist ein Fehler aufgetreten ! */
  94.     }
  95.    else
  96.     {
  97.      yalt=FunktionsWert(nr,xmn,Ableitung);
  98.      if(StartBlock->Fehler)flagg=2; /* NICHT MatheFehler */
  99.      xalt=xmn;
  100.      Verbinden(xalt,yalt);
  101.      
  102.      for (Pos=1+Genauigkeiten[GE];Pos<=MaxXPos;Pos+=Genauigkeiten[GE])
  103.       {
  104.        i=Div(Sub(Flt(Pos),x0),xm);
  105.        /* Berechnet für einige x-Werte den Funktionswert und zeichnet ihn */
  106.        y=FunktionsWert(nr,i,Ableitung);
  107.        
  108.        if(StartBlock->Fehler)
  109.         {
  110.          flagg=2;
  111.         }
  112.        Plotte(nr,xalt,i,yalt,y,0,Ableitung); /* Zeichnet den Punkt */
  113.        xalt=i;
  114.        yalt=y;
  115.        /* Abfrage auf Unterbrechnung */
  116.        H=EventAbfrage(Window,&msgInfo);
  117.        if (H==MOUSEBUTTONS)
  118.         {
  119.          if(request(BE_JA,BE_NEIN,BE_QUEST))
  120.           {
  121.            Pos=MaxXPos;
  122.            ZEICHNEN=FALSE;
  123.           }
  124.         }
  125.       }
  126.      
  127.      if(ZEICHNEN)
  128.       {
  129.        y=FunktionsWert(nr,xmp,Ableitung);
  130.        Plotte(nr,xalt,xmp,yalt,y,0,Ableitung); /* Zeichnet den letzten Punkt */
  131.       }
  132.      
  133.      /* Alles, was in FARBE3 über den Rand hinausgezeichnet wurde, wird hier gelöscht.*/
  134.      /* Dabei wird auch alles FARBE1 gelöscht. Beim Überschreiben wird darauf         */
  135.      /* geachtet, daß FARBE3 nicht beeinträchtigt wird. Es wird nur ein Bit in der    */
  136.      /* ersten BitPlane gesetzt, wenn dort FARBE3 erscheinen soll. Die zweite         */
  137.      /* BitPlane wird nicht berührt.                                                  */
  138.      
  139.      WaitBlit();
  140.      Forbid();
  141.      SetAPen(RastPort,FARBE0);
  142.      RectFill(RastPort,0,yy+Abstand+1,999,299);
  143.      RectFill(RastPort,0,0,1000,Abstand);
  144.      SetAPen(RastPort,FARBE1);
  145.      /* Und neu zeichnen */
  146.      SetWrMsk(RastPort,1);
  147.      
  148.      if(Cmp(x0,0.0)>=0 && (Fix(x0)<(xx)))
  149.       {
  150.        Line(x0,1.0,x0,Flt(yy));
  151.       }
  152.      if(Cmp(y0,0.0)>=0 && Cmp(y0,Flt(yy))<1)
  153.       {
  154.        Line(1.0,y0,Flt(xx),y0);
  155.       }
  156.      zeichne();
  157.      SetWrMsk(RastPort,0xff);
  158.      Permit();
  159.      
  160.      KoordinatenKreuz_gezeichnet=TRUE;
  161.      FehlerAbfrage(); /* Ist ein Fehler aufgetreten ? */
  162.     }
  163.    while(H=EventAbfrage(Window,&msgInfo));
  164.    ModifyIDCMP(Window,OldIDCMP);
  165.    Free_Block(StartBlock);
  166.   }
  167.  
  168.  /* Arbeitet rekursiv, bis y-Abstand zweier Punkte klein genug */
  169.  VOID Plotte(nr,xl,xr,yl,yr,st,Ableitung)
  170.  unsigned short nr;
  171.  double xl,xr,yr,yl;
  172.  int st,Ableitung;
  173.   {
  174.    double x,y,a;
  175.    SHORT a1;
  176.    long Sprung;
  177.    
  178.    /* GE liegt zwischen 1 und 3 */
  179.    Sprung=4-GE;
  180.    a=Sub(yl,yr);
  181.    if(Cmp(Abs(a),MAXLONG)==1)
  182.     {
  183.      a1=0;
  184.     }
  185.    else
  186.     {
  187.      a1=(abs(Fix(a))>Sprung);
  188.     }
  189.    /* Großer Sprung zwischen 2 Werten (z.B. Pole) */
  190.    if(a1)
  191.     {
  192.      /* Rekursionstiefe aufgrund der Zeichengenauigkeit */
  193.      if(st<=10 && Cmp(Min(yl,yr),Flt(yy))==-1 && Tst(Max(yr,yl))==1)
  194.       {
  195.        x=Div((Add(xl,xr)),2.0); /* x-Wert zwischen den beiden Stellen */
  196.                                 /* Berechnen des Funktionswertes      */
  197.        y=FunktionsWert(nr,x,Ableitung);
  198.        Plotte(nr,xl,x,yl,y,st+1,Ableitung);
  199.        Plotte(nr,x,xr,y,yr,st+1,Ableitung);
  200.       }
  201.      else
  202.       {
  203.        flagg=1; /* 2 Punkte werden nicht verbunden */
  204.                 /* z. B. 1/x bei x um 0            */
  205.        Verbinden(xr,yr);
  206.       }
  207.     }
  208.    else
  209.     {
  210.      Verbinden(xr,yr);
  211.     }
  212.   }
  213.  
  214.  double FunktionsWert(nr,i,Ableitung)
  215.  int Ableitung;
  216.  unsigned short nr;
  217.  double i;
  218.   {
  219.    double ywert;
  220.    double y;
  221.    switch(Ableitung)
  222.     {
  223.      case 0:
  224.       {
  225.        MatheFehler|=Calc_P(&ywert,StartBlock,&i);
  226.        goto Einsprung_B1;
  227.       }
  228.      case 1:    
  229.       {
  230.        double H1,H2,Help1;
  231.        if(Ableitung==1)
  232.         {
  233.          Help1=(Add(i,deltah));
  234.          MatheFehler|=Calc_P(&H1,StartBlock,&Help1);
  235.          MatheFehler|=Calc_P(&H2,StartBlock,&i);
  236.          ywert=Div(Sub(H1,H2),deltah);
  237.          Einsprung_B1:
  238.          y=Sub(y0,Mul(ym,ywert));
  239.          break;
  240.         }
  241.        case 2:      
  242.         {
  243.          Help1=Add(i,deltahh);
  244.          H1=FunktionsWert(nr,i,1);
  245.          H2=FunktionsWert(nr,Help1,1);
  246.          ywert=Div(Sub(H1,H2),deltahh);
  247.          y=Sub(y0,ywert);
  248.          break;
  249.         }
  250.       }
  251.     }
  252.    return(y);
  253.   }
  254.  
  255.  
  256.  VOID Verbinden(xr,yr)
  257.  double xr,yr;
  258.   {
  259.    xr=Add(x0,Mul(xm,xr));
  260.    
  261.    if(Cmp(Abs(yr),MAXLONG)==-1)
  262.     {
  263.      /* Wenn zu zeichen (innerhalb Zeichenbereichs) */
  264.      switch(flagg)
  265.       {
  266.        /* 2 Punkte nicht verbinden */
  267.        case 1:
  268.         {
  269.          Pset(xr,yr);
  270.          flagg=0;
  271.          break;
  272.         }
  273.        case 2:
  274.         {
  275.          flagg=1;
  276.          break;
  277.         }
  278.        case 0: 
  279.         {
  280.          /* Zum nächsten Punkt zeichnen. Wenn Koordinaten wie bei Pset, dann */
  281.          /* wird nur ein Punkt gesetzt.                                      */
  282.          DrawTo(xr,yr);
  283.          break;
  284.         }
  285.       }
  286.     }
  287.    else
  288.     {
  289.      flagg=1;
  290.     }
  291.   }
  292.  
  293.  DOUBLE Max(a,b)
  294.  DOUBLE a,b;
  295.   {
  296.    if(a>b)
  297.     {
  298.      return(a);
  299.     }
  300.    else
  301.     {
  302.      return(b);
  303.     }
  304.   }
  305.  
  306.  DOUBLE Min(a,b)
  307.  DOUBLE a,b;
  308.   {
  309.    if(a>b)
  310.     {
  311.      return(b);
  312.     }
  313.    else
  314.     {
  315.      return(a);
  316.     }
  317.   }
  318.  
  319.   /* Hier kommen die Stub-Routinen, die für dieses Programm nicht */
  320.   /* gebraucht werden. Dadurch werden sie nicht angelinkt.        */
  321.  VOID MemCleanup(VOID)
  322.   {
  323.   }
  324.  
  325.  
  326.  VOID chkabort(VOID)
  327.   {
  328.   }
  329.  
  330.  
  331.  
  332.