|
Registriert seit: 18. Jan 2008 594 Beiträge |
#2
irgendwie haut das ganze net wirklich hin: was ist x0? diese variable wird nirgends belegt, ist also 0, sprich du zeichnest ein rechteck von -1 bis 0?
Hier mal Code aus meinem Plotter:
Delphi-Quellcode:
dies ist code aus meinem Funktionsplotter!
function Graph2D : ErrorCode;
var ImageHeight : integer; ImageLength : integer; YAchse : integer; XAchse : integer; XGitterabstand : extended; YGitterabstand : extended; u : integer; x : extended; xmin,xmax,ymin,ymax : extended; begin xmin := Graph_xmin; xmax := Graph_xmax; ymin := Graph_ymin; ymax := Graph_ymax; ImageLength := graph_image_2D.Width; ImageHeight := graph_image_2D.Height; // Berechen der y_Achse und X_Achse YAchse := Round(ImageLength - ImageLength / abs(xmax - xmin) * xmax) ; XAchse := Round(ImageHeight + ImageHeight / abs(ymax - ymin) * ymin) ; XGitterabstand := ImageLength / abs(xmax - xmin); YGitterabstand := ImageHeight / abs(ymax - ymin); // Gitterabstände anpassen if XGitterabstand < 25 then XGitterabstand := 25; if XGitterabstand > 250 then XGitterabstand := 250; if YGitterabstand < 20 then YGitterabstand := 20; if YGitterabstand > 150 then YGitterabstand := 150; with graph_image_2D.canvas do begin brush.color := clwhite; rectangle(0,0,ImageLength + 1,ImageHeight + 1); // Gitternetz zeichnen pen.Color := $00E0E0E0; pen.width := 1; u := 1; repeat moveto(YAchse - round(u * XGitterabstand),0); lineto(YAchse - round(u * XGitterabstand),ImageHeight); inc(u); until YAchse - round(u * XGitterabstand) < 0; u := 1; repeat moveto(YAchse + round(u * XGitterabstand),0); lineto(YAchse + round(u * XGitterabstand),ImageHeight); inc(u); until YAchse + round(u * XGitterabstand) > ImageLength; u := 1; repeat moveto(0,XAchse - round(u * YGitterabstand)); lineto(ImageLength,XAchse - round(u * YGitterabstand)); inc(u); until XAchse - round(u * YGitterabstand) < 0; u := 1; repeat moveto(0,XAchse + round(u * YGitterabstand)); lineto(ImageLength,XAchse + round(u * YGitterabstand)); inc(u); until XAchse + round(u * YGitterabstand) > ImageHeight; pen.Color := clblack; // Striche für Zahlen zeichnen u := 1; repeat moveto(YAchse - round(u * XGitterabstand),XAchse - 5); lineto(YAchse - round(u * XGitterabstand),XAchse + 5); inc(u); until YAchse - round(u * XGitterabstand) < 0; u := 1; repeat moveto(YAchse + round(u * XGitterabstand),XAchse - 5); lineto(YAchse + round(u * XGitterabstand),XAchse + 5); inc(u); until YAchse + round(u * XGitterabstand) > ImageLength; u := 1; repeat moveto(YAchse - 5,XAchse - round(u * YGitterabstand)); lineto(YAchse + 5,XAchse - round(u * YGitterabstand)); inc(u); until XAchse - round(u * YGitterabstand) < 0; u := 1; repeat moveto(YAchse - 5,XAchse + round(u * YGitterabstand)); lineto(YAchse + 5,XAchse + round(u * YGitterabstand)); inc(u); until XAchse + round(u * YGitterabstand) > ImageHeight; // X-Achse + Y-Achse zeichnen pen.Color := clblack; pen.Width := 2; moveto(0,XAchse); lineto(ImageLength + 1,XAchse); moveto(YAchse,0); lineto(YAchse,ImageHeight + 1); brush.Color := clblack; polygon([point(YAchse - 4,12),point(YAchse + 4,12),point(YAchse,0),point(YAchse - 4,12)]); polygon([point(ImageLength - 12,XAchse - 4),point(ImageLength - 12,XAchse + 4),point(ImageLength,XAchse),point(ImageLength - 12,XAchse - 4)]); // Beschriftung font.Height := 10; font.Color := clblack; brush.Color := clwhite; font.Name := 'MS Sans Serif'; u := 1; repeat if XGitterabstand = 25 then textout(YAchse - round(u * XGitterabstand) + 4,XAchse + 10, floattostr(round(x_wert(xmin,xmax,YAchse - u * XGitterabstand,ImageHeight,ImageLength)))) else if XGitterabstand = 250 then textout(YAchse - round(u * XGitterabstand) + 4,XAchse + 10, floattostr(roundto(x_wert(xmin,xmax,YAchse - u * XGitterabstand,ImageHeight,ImageLength),-3))) else textout(YAchse - round(u * XGitterabstand) + 4,XAchse + 10, floattostr(- u)); inc(u); until YAchse - round(u * XGitterabstand) < 0; u := 1; repeat if XGitterabstand = 25 then textout(YAchse + round(u * XGitterabstand) + 4,XAchse + 10, floattostr(round(x_wert(xmin,xmax,YAchse + u * XGitterabstand,ImageHeight,ImageLength)))) else if XGitterabstand = 250 then textout(YAchse + round(u * XGitterabstand) + 4,XAchse + 10, floattostr(roundto(x_wert(xmin,xmax,YAchse + u * XGitterabstand,ImageHeight,ImageLength),-3))) else textout(YAchse + round(u * XGitterabstand) + 4,XAchse + 10, floattostr( u)); inc(u); until YAchse + round(u * XGitterabstand) > ImageLength; u := 1; repeat if YGitterabstand = 20 then textout(YAchse - 17,XAchse - round(u * YGitterabstand) - 15, floattostr(round(y_wert(ymin,ymax,XAchse - round(u * YGitterabstand),ImageHeight,ImageLength)))) else if YGitterabstand = 150 then textout(YAchse - 17,XAchse - round(u * YGitterabstand) - 15, floattostr(roundto(y_wert(ymin,ymax,XAchse - round(u * YGitterabstand),ImageHeight,ImageLength),-3))) else textout(YAchse - 17,XAchse - round(u * YGitterabstand) - 15, floattostr( u)); inc(u); until XAchse - round(u * YGitterabstand) < 0; u := 1; repeat if YGitterabstand = 20 then textout(YAchse - 17,XAchse + round(u * YGitterabstand) - 15, floattostr(round(y_wert(ymin,ymax,XAchse + round(u * YGitterabstand),ImageHeight,ImageLength)))) else if YGitterabstand = 150 then textout(YAchse - 17,XAchse + round(u * YGitterabstand) - 15, floattostr(roundto(y_wert(ymin,ymax,XAchse + round(u * YGitterabstand),ImageHeight,ImageLength),-3))) else textout(YAchse - 17,XAchse + round(u * YGitterabstand) - 15, floattostr(- u)); inc(u); until XAchse + round(u * YGitterabstand) > ImageHeight; end; end; function Tfrm2D.Graph2D_Funktion(Funktion : string ;Farbe : TColor; Breite : integer; ClearGraph : boolean): ErrorCode ; var ImageHeight : integer; ImageLength : integer; YAchse : integer; XAchse : integer; tmp_x : extended; u : integer; x, y : extended; Variable : char; xmin,xmax,ymin,ymax : extended; begin xmin := Graph_xmin; xmax := Graph_xmax; ymin := Graph_ymin; ymax := Graph_ymax; Variable := Funktionsvariable; Funktion := SyntaxPruefung(Funktion,Variable); ImageLength := graph_image_2D.Width; ImageHeight := graph_image_2D.Height; // Berechen der y_Achse und X_Achse YAchse := Round(ImageLength - ImageLength / abs(xmax - xmin) * xmax) ; XAchse := Round(ImageHeight + ImageHeight / abs(ymax - ymin) * ymin) ; if ClearGraph then Graph2D(); graph_image_2D.Canvas.Pen.Color := Farbe; graph_image_2D.Canvas.Pen.Width := Breite; tmp_x := abs(xmax - xmin) / ImageLength; x := xmin - tmp_x ; if Funktion = '' then exit; y := EF32_Funktionswert(Funktion,Variable,x); graph_image_2D.Canvas.MoveTo(x_pixel(xmin,xmax,x,ImageHeight,ImageLength),y_Pixel(ymin,ymax,y,ImageHeight,ImageLength)); x := xmin; for u := - 1 to ImageLength do begin y := EF32_Funktionswert(Funktion,Variable,x); graph_image_2D.Canvas.LineTo(x_pixel(xmin,xmax,x,ImageHeight,ImageLength),y_Pixel(ymin,ymax,y,ImageHeight,ImageLength)); x := x + tmp_x; end; end; der Plotter hängt auch mit an! |
![]() |
Ansicht |
![]() |
![]() |
![]() |
ForumregelnEs ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.
BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus. Trackbacks are an
Pingbacks are an
Refbacks are aus
|
|
Nützliche Links |
Heutige Beiträge |
Sitemap |
Suchen |
Code-Library |
Wer ist online |
Alle Foren als gelesen markieren |
Gehe zu... |
LinkBack |
![]() |
![]() |