Registriert seit: 19. Sep 2013
Ort: Braunschweig
204 Beiträge
Delphi 6 Professional
|
AW: Probleme mit Sinus Darstellung
2. Mär 2015, 12:32
Delphi-Quellcode:
type
TFxFunction = function(const x: Extended): Extended;
TPointDynArray = array of TPoint;
function CalculatePointView
(AFunc: TFxFunction; const ARect: TRect; x0, y0, dx, dy: double): TPointDynArray;
var
x, y: double;
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 :double;
P: TPointDynArray;
begin
R := Rect (GapLeft,
GapTop,
Width - GapRight + 2,
Height - GapBottom);
Canvas.Brush.Color := FHistoBkColor;
Canvas.Pen.Color := FHistoBkColor;
Canvas.Pen.Style := psSolid;
Canvas.FillRect(R);
InflateRect(R, -1, -1);
x0 := 0;
y0 := 3;
dx := 0.05;
dy := 0.05;
P := CalculatePointView(sin, R, x0, y0, dx, dy));
Canvas.Pen.Color := cllime;
CalculatePointView(Canvas, R, P);
end;
Christian
|
|
Zitat
|