Einzelnen Beitrag anzeigen

Chris211183

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

AW: Probleme mit Sinus Darstellung

  Alt 3. Mär 2015, 10:45
Delphi-Quellcode:
function THixHistoGraph.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 THixHistoGraph.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 (FGapLeft,
              FGapTop,
              Width - FGapRight + 2,
              Height - FGapBottom);

   Canvas.Brush.Color := FHistoBkColor;
   Canvas.Pen.Color := FHistoBkColor;
   Canvas.Pen.Style := psSolid;
   Canvas.FillRect(R);
   InflateRect(R, -1, -1);
   x0 := FXScale.ValMin;
   y0 := FYScale.ValMax;
   dx := 0.05;
   dy := 0.05;
   P := CalculatePointView(@System.sin, R, x0, y0, dx, dy);
   Canvas.Pen.Color := cllime;
   DrawPointView(Canvas, R, P);
end;

Trotzdem immer der selbe Scheiß, macht er nicht
Christian

Geändert von Chris211183 ( 3. Mär 2015 um 10:47 Uhr)
  Mit Zitat antworten Zitat