![]() |
AW: Probleme mit Sinus Darstellung
Eine stehende Welle könnte man in den Code in etwa so implementieren (hab den Code von Blup jetzt aber nicht probiert).
Delphi-Quellcode:
function FX1(const X: double): double;
begin Result := 2 * Sin(X + DeltaX); end; function FX2(const X: double): double; begin Result := 2 * Sin(DeltaX - X + Pi); end; function FX3(const X: double): double; begin Result := FX1(X) + FX2(X); end; procedure TFTest.StartDrawButtonClick(Sender: TObject); begin DeltaX := 0; DrawTimer.Interval := 50; DrawTimer.Enabled := true; end; procedure TFTest.StopDrawButtonClick(Sender: TObject); begin DrawTimer.Enabled := false; end; procedure TFTest.DrawTimerTimer(Sender: TObject); begin DrawTimer.Enabled := false; try PaintBox1.Invalidate; DeltaX := DeltaX + PI / 18; Application.ProcessMessages; finally DrawTimer.Enabled := true; end; end; procedure TFTest.PaintBox1Paint(Sender: TObject); .. P := BerechnePunkteDarstellung(FX1, R, x0, y0, dx, dy); Canvas.Pen.Color := clBlue; ZeichnePunkteDarstellung(Canvas, R, P); P := BerechnePunkteDarstellung(FX2, R, x0, y0, dx, dy); Canvas.Pen.Color := clRed; ZeichnePunkteDarstellung(Canvas, R, P); P := BerechnePunkteDarstellung(FX3, R, x0, y0, dx, dy); Canvas.Pen.Color := clLime; ZeichnePunkteDarstellung(Canvas, R, P); end; end; |
AW: Probleme mit Sinus Darstellung
Zitat:
( erwartet aber , gefunden ???:gruebel: habe das so probiert
Delphi-Quellcode:
dann kommt inkompatible Typen....
P := CalculatePointView(sin(r,x0, y0, dx, dy));
hat mein Compiler heute Montag oder was ist daran falsch ??? |
AW: Probleme mit Sinus Darstellung
Die Typdeklarationen hast Du aber mit kopiert?
Zitat:
|
AW: Probleme mit Sinus Darstellung
na logo, alles wie beschrieben und auf mein Code umgesetzt ! das ist auch das Einzige, was rumzickt
|
AW: Probleme mit Sinus Darstellung
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; |
AW: Probleme mit Sinus Darstellung
TFxFunction wurde mit Extendet-Parameter und -Rückgabewert deklariert, da die sin-Funktion in Unit Math so deklariert ist.
Entweder du stellst die Definition auf Double um oder die Parameter und Rückgabewerte der neuen Funktionen auf Extendet. |
AW: Probleme mit Sinus Darstellung
Ahhhh, jetzt ja ! Danke !
Ihr seid immer wieder klasse ! Da lernt man richtig was ! |
AW: Probleme mit Sinus Darstellung
Okay, hab jetzt alle als Extended deklariert, er macht glaube ich mucken mit dem Rectangle, da dieses ja Rückgabewerte vom Typ Integer hat.
habs mit Trunc und Round probiert, meckert er weiter, vonwegen inkompatible Typen... |
AW: Probleme mit Sinus Darstellung
Siehe Kommentar
Zitat:
|
AW: Probleme mit Sinus Darstellung
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; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:03 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz