Entwickler-Ecke

Multimedia / Grafik - TCanvas - Kreisprozedur


Nightwalker_Z - Do 05.12.02 20:48
Titel: TCanvas - Kreisprozedur
Hallihallo
Ich möchte gerne ein Plottersimulationsprogramm entwerfen.
Ich frage mich, wie man einen Kreis auf einem Canvas darstellen kann
Ich will in etwa so eine Prozedur schreiben:


Quelltext
1:
procedure Drawcircle(x_start,y_start,x_zw,y_zw,x_end,y_end);                    


Diese Prozedur soll einen (nicht vollständigen) Kreis zeichnen, der durch die drei Punkte geht...
--> Kreis fängt bei (x_start|y_start) an und endet bei (x_end|y_end).
Klar.. es gibt die Funktion Arc oder Circle, aber die will ich nicht verwenden, weil die meinen Kreis SOFORT auf mein Canvas draufklatschen... ich will das Ding Pixel für Pixel selber zeichnen....


Wäre dankbar für Antworten ....
Greetz
Nightwalker_Z :twisted:


Anonymous - Do 05.12.02 21:11

Hab schon mal auf so eine Frage geantwortet. Der Typ hat auf die Antworten nicht reagiert. Deshalb nur ein Link:

http://spotlight.de/zforen/dlp/m/dlp-1037579526-18798.html


Nightwalker_Z - Fr 06.12.02 11:11

Danke für die Antwort - jedoch ist das nicht ganz, was ich brauche.
Wie gesagt - ich will ja auch so ne Art Kreisbogen zeichnen - keinen ganzen Kreis...

@Popoy: Die zweite Variante des Quellcodes, die du angegeben hast ist nicht schlecht... Aber wie sieht das nur mit dem Bogen aus ???

Erinnerung:

Quelltext
1:
 procedure ZeichneKreis(x_start,y_start,x_zw,y_zw,x_end,y_end:integer);                    

:shock:

Nightwalker_Z


Anonymous - Fr 06.12.02 11:28

Das ist nur noch Mathematik


Nightwalker_Z - Fr 06.12.02 13:35

LOL :lol:

klar isses Mathematik - bin eben ein bisserl faul
Hab gedacht jemand hätte sowas schon vorgefertigt gehabt, dass ich mir nicht so nen Kopf machen muss.
Naja - that's Life 8)

Gruß
Nightwalker


Sven - Fr 06.12.02 13:50

Hi, entschuldigt wenn ich mich einmische. Aber ich verwende folgenden Code um eine Ellipse zu zeichnen. Die Prozedur kann man auch zum zeichnen eines Kreises verwenden.


Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
Type
  TFPoint = record
    X, Y : double;
  end;

....

procedure _DrawEllipse(const xfp: array of TFPoint);
  var i, j, rad, rad2, estep,
      xRot, yRot               : integer;
      cm, p1, p2, p3, p4, p5   : TPoint;
      p3f, p4f, p5f, theta,
      aWinkel, bWinkel,
      RAngle, r1, r2           : double;
begin
  cm  := CnvToP(xfp[0]);
  p2  := CnvToP(xfp[1]);
  p3f := xfp[2].x;
  p4f := xfp[3].x;
  p5f := xfp[4].x;
  r1 := Abs(Radius(cm.x, cm.y, p2.x, p2.y));
  r2 := Abs(r1 * p3f);
  RAngle  := Winkel(xfp[0].X, xfp[0].Y, xfp[1].X, xfp[1].Y) * (PI/180);
  aWinkel := p4f;
  bWinkel := p5f;
  if isZero(bWinkel-aWinkel) then begin
    aWinkel := 0;
    bWinkel := 360
  end;
  theta   := aWinkel * (PI/180);
  // Ellipse (x,y) coordinates [pre-rotation]
  p1.x := Round(cm.x + r1*COS(theta));
  p1.y := Round(cm.y + r2*SIN(theta));
  xRot := Round(cm.x + (p1.x - cm.x)* COS(RAngle)
                     - (p1.y - cm.y)* SIN(RAngle) );
  yRot := Round(cm.y - (p1.x - cm.x)* SIN(RAngle)
                     - (p1.y - cm.y)* COS(RAngle) );
  BCAD.xDraw.Canvas.MoveTo(xRot, yRot);
  estep := Trunc(bWinkel - aWinkel);
  for j := 1 to estep do begin
    theta := (aWinkel+j) * (PI/180);
    // Ellipse (x,y) coordinates [pre-rotation]
    p1.x := Round(cm.x + r1*COS(theta));
    p1.y := Round(cm.y + r2*SIN(theta));
    xRot := Round(cm.x + (p1.x - cm.x)* COS(RAngle)
                       - (p1.y - cm.y)* SIN(RAngle) );
    yRot := Round(cm.y - (p1.x - cm.x)* SIN(RAngle)
                       - (p1.y - cm.y)* COS(RAngle) );
    BCAD.xDraw.Canvas.LineTo(xRot, yRot)
  end;
  theta := bWinkel * (PI/180);
  // Ellipse (x,y) coordinates [pre-rotation]
  p1.x := Round(cm.x + r1*COS(theta));
  p1.y := Round(cm.y + r2*SIN(theta));
  xRot := Round(cm.x + (p1.x - cm.x)* COS(RAngle)
                     - (p1.y - cm.y)* SIN(RAngle) );
  yRot := Round(cm.y - (p1.x - cm.x)* SIN(RAngle)
                     - (p1.y - cm.y)* COS(RAngle) );
  BCAD.xDraw.Canvas.LineTo(xRot, yRot);
end; {DrawEllipse}