Einzelnen Beitrag anzeigen

Chris211183

Registriert seit: 19. Sep 2013
Ort: Braunschweig
204 Beiträge
 
Delphi 6 Professional
 
#30

AW: Probleme mit Sinus Darstellung

  Alt 2. Mär 2015, 13:01
Stimmt, denn och ändert das die Typeninkompatibilität nicht....


Hier nochmal mein Code mit den Änderungen

Delphi-Quellcode:
TFxFunction = function(const x: Extended): Extended;
TPointDynArray = array of TPoint;



function CalculatePointView
(AFunc: TFxFunction; const ARect: TRect; x0, y0, dx, dy: Extended): TPointDynArray;
var
  x, y: Extended;
  i : integer;
begin // für jede Spalte einen Punkt
   SetLength(Result, ARect.Right - ARect.Left +1); // Punkte berechnen
   x := x0;
   for i := Low(Result) to High(Result) do
   begin
   y := AFunc(x);
   y := -y; // Canvas Nullpunkt obere linke Ecke mit Y- Achse nach unten !!!
   y := y0 + y; // oberen Rand Addieren
   y := y / dy; // Skalieren
   Result[i].x := ARect.Left +1;
   Result[i].Y := ARect.Top + Round(y); // runden
   x := x + dx;
   end; // nächster Punkt
end;

procedure DrawPointView
(ACanvas: TCanvas; const ARect: TRect; const APoints : TPointDynArray);
var
   h : Thandle;
   begin
   h:= SaveDC(ACanvas.Handle);
   try
   IntersectClipRect(ACanvas.Handle, ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
   Polyline(ACanvas.Handle, APoints[0], Length(APoints));
   finally
      RestoreDC(ACanvas.Handle, h);
   end;
end;

procedure THixHistoGraph.DrawFunction;
var
  R :TRect;
  x0, y0, dx, dy :Extended;
  P: TPointDynArray;
  begin
   R := Rect (trunc(FGapLeft),
              trunc(FGapTop),
              trunc(Width - FGapRight + 2),
              trunc(Height - FGapBottom));

   Canvas.Brush.Color := FHistoBkColor;
   Canvas.Pen.Color := FHistoBkColor;
   Canvas.Pen.Style := psSolid;
   Canvas.FillRect(R);
   InflateRect(R, -1, -1);
   x0 := 0.0;
   y0 := 3.0;
   dx := 0.05;
   dy := 0.05;
   P := CalculatePointView(sin, R, x0, y0, dx, dy));
   Canvas.Pen.Color := cllime;
   DrawPointView(Canvas, R, P);
end;
Christian
  Mit Zitat antworten Zitat