Autor Beitrag
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Mo 05.06.06 22:07 
hat jemand eine Idee wie ich in einer Canvas einen Kreisbogen zeichnen kann? also mit beliebiger Grad Zahl?
das heisst zum beispiel einen bogen wie den folgenden:

user defined image

das graue soll nicht gezeichnet werden (nur zur verdeutilichung...) aber wie macht man sowas? also mit X,Y,radius und Winkel

mfG Green
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Mo 05.06.06 22:14 
Hi!
die Antwort ist Arc()...einfach nur Arc().... :)
MFG, Arno Nym
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Mo 05.06.06 22:25 
danke, aber was muss ich machen um diese version von Arc zu verwenden?
ausblenden Delphi-Quelltext
1:
procedure Arc(X, Y, W, H, Angle, AngleLength: Integer); overload;					
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 05.06.06 22:40 
Ich würde in diesem Fall direkt an ide Delphi Hilfe verweisen

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Mo 05.06.06 22:44 
Hi!
hm, diese Version steht zwar in der Hilfe, ist aber gar nich implementiert, jedenfalls hab ichs nicht gefunden...
Sieht so aus als wenn du sie selber schreiben musst :)
Naja, Ich versuch mal schnell die Funktion zu implementieren...
MFG, Arno Nym
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Mo 05.06.06 22:48 
Zitat:
Draws an arc on the image along the perimeter of the ellipse bounded by the specified rectangle.

procedure Arc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer); overload;
procedure Arc(X, Y, W, H, Angle, AngleLength: Integer); overload;

Description

Use Arc to draw an elliptically curved line with the current Pen. The arc traverses the perimeter of an ellipse that is bounded by the points (X1,Y1) and (X2,Y2). The arc is drawn following the perimeter of the ellipse, counterclockwise, from the starting point to the ending point. The starting point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X3,Y3). The ending point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X4, Y4).

Use the second syntax to draw an arc defined by the rectangle (X,Y,W,H), the start angle Angle and the arc length AngleLength.

The angles Angle and AngleLength are 1/16th of a degree. For example, a full circle equals 5760 (16*360). Positive values of Angle and AngleLength mean counter-clockwise while negative values mean clockwise direction. Zero degrees is at the 3'o clock position.

Note: If you are developing a cross platform application and also targeting Windows 95, the sums X1 + X2 and Y1 + Y2 cannot exceed 32768. Also, the sum X1 + X2 + Y1 + Y2 cannot exceed 32768.


steht so in der Delphi Ide Help
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 05.06.06 22:52 
In Delphi 2005 ist die zweite Version auch in der Hilfe nicht mehr enthalten. Das wurde anscheinend korrigiert.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Mo 05.06.06 23:19 
Hi!
also, falls du mit Winkeln arbeiten willst, hab ich nochmal eine arc-Funktion für dich geschrieben:
ausblenden Delphi-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:
//Zeichnet einen Kreisausschnitt um den Mittelpunkt X,Y. R ist der Radius.
//Startangle der Startwinkel im Bogenmaß, EndAngel der EndWinkel im Bogenmaß
Procedure drawarc(C:TCanvas;X,Y,R:Integer;startangle,endangle:real);
var p1,p2: TPoint;
    temp,factor,runner : real;
begin;
 IF startangle > endangle then begin;
  temp := startangle;
  startangle := endangle;
  endangle := temp;
 end;
 runner := startangle;
 p1.X := round(cos(runner)*R+X);
 p1.Y := round(sin(runner)*R+Y);
 factor := PI/R;
 While runner < endangle do begin;
  runner := runner + factor;
  p2.X := round(cos(runner)*R+X);
  p2.Y := Y-round(sin(runner)*R);
  C.MoveTo(p1.X,p1.Y);
  C.LineTo(p2.X,p2.Y);
  P1 := P2;
 end;
end;

Hier z.B. der Aufruf für einen Viertelkreis im ersten Quadranten auf der Fläche eines Formulars:
ausblenden Delphi-Quelltext
1:
drawarc(Form1.Canvas,round(Form1.Width/2),round(Form1.Height/2),MIN(round(Form1.Width/2),round(Form1.Height/2)),0,PI/2);					


MFG, Arno Nym
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Di 06.06.06 10:13 
hmm, also ich versteh die proc nit so ganz, wenn ich dein Beispiel nehm bekomm ich MIN is unnknown identifier, und nach ein bissel ausprobieren hab ich das da für einen ViertelKreis:
ausblenden Delphi-Quelltext
1:
DrawArc(Image1.Canvas,100,100,50,0,PI/2);					

die params X,Y und R sind klar, aber StartAngel und Endangel sind mir nich so klar, zum Beispiel fängt der Kreis bei StartAngel 0 ganz Rechts an und bei Startangel 1 hab ich plötzlich eine Gerade im Bild...
ausblenden Delphi-Quelltext
1:
DrawArc(Image1.Canvas,100,100,50,1,PI/2);					


kannst du mir helfen?
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Di 06.06.06 11:03 
Hi!
Ja, das mit der Gerade habe ich eben behoben, und noch einen anderen Bug. Hier ist die neue Procedure:
MIN ist ein Befehl aus der Unit "math" die muss man natürlich vorher einbinden wenn man MIN benutzen will,
aber das war ja auch nur ein Beispiel.

ausblenden Delphi-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:
//Zeichnet einen Kreisausschnitt um den Mittelpunkt X,Y. R ist der Radius.
//Startangle der Startwinkel im Bogenmaß, EndAngel der EndWinkel im Bogenmaß
Procedure drawarc(C:TCanvas;X,Y,R:Integer;startangle,endangle:real);
var p1,p2: TPoint;
    temp,factor,runner : real;
begin;
 IF startangle > endangle then begin;
  temp := startangle;
  startangle := endangle;
  endangle := temp;
 end;
 //C.Rectangle(X-R,Y-R,X+R,Y+R);
 C.Pixels[X,Y] := clred;
 runner := startangle;
 p1.X := round(cos(runner)*(R-1)+X);
 p1.Y := Y-round(sin(runner)*(R-1));
 factor := PI/R;
 While runner < endangle do begin;
  runner := runner + factor;
  p2.X := round(cos(runner)*(R-1)+X);
  p2.Y := Y-round(sin(runner)*(R-1));
  C.MoveTo(p1.X,p1.Y);
  C.LineTo(p2.X,p2.Y);
  P1 := P2;
 end;
end;


MFG, Arno Nym
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Do 08.06.06 10:07 
k danke, ich denke das müsste klappen, aber was muss ich denn in der proc ändern um IM UHRZEIGERSINN zu drehen? weil so drehts ja von rechts nach links, ich bräuchte es aber von Links nach rechts...

mfG Green
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Do 08.06.06 11:10 
Hi!
Auch noch Extrawünsche oder wat ??? :D
Also hier die End-Version der Funktion die auch gegen den Urzeigersinn zeichnen kann (startangle > endangle)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Procedure drawarc(C:TCanvas;X,Y,R:Integer;startangle,endangle:real);
var p1,p2: TPoint;
    factor,runner : real;
begin;
 //C.Rectangle(X-R,Y-R,X+R,Y+R);
 C.Pixels[X,Y] := clred;
 runner := startangle;
 p1.X := round(cos(runner)*(R-1)+X);
 p1.Y := Y-round(sin(runner)*(R-1));
 IF startangle < endangle Then factor := PI/R
 Else factor := -PI/R;
 While ((startangle < endangle) AND (runner < endangle))
 OR ((startangle > endangle) AND (runner > endangle))
 do begin;
  runner := runner + factor;
  p2.X := round(cos(runner)*(R-1)+X);
  p2.Y := Y-round(sin(runner)*(R-1));
  C.MoveTo(p1.X,p1.Y);
  C.LineTo(p2.X,p2.Y);
  P1 := P2;
 end;
end;


MFG, Arno Nym
Sors
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 47

Win XP
D7 Prof
BeitragVerfasst: So 21.01.07 19:41 
Titel: Bogen zeichnen
Hab da lange drüber gegrübelt. Versteh das leider auch ned. Gibts ned noch irgendwie ne bessere Lösung??
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: So 21.01.07 19:47 
Die Koordinaten stellen in deinem Fall die Koordinaten eines virtuellen Koordinatensystems da oder bezüglich der Grafik in die du malst also die Position in der Bitmap?

//Edit: Wie bin ich eigentlich vor den Post von Sors gekommen eigentlcih wollte ich auf ihn antworten?:gruebel:


Zuletzt bearbeitet von Allesquarks am So 21.01.07 22:17, insgesamt 1-mal bearbeitet
Sors
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 47

Win XP
D7 Prof
BeitragVerfasst: So 21.01.07 20:29 
Titel: Kreisbogen
Hier nochmal mein Problem:

Es soll in meinem Programm ein Kreisbogen gezeichnet werden, nur anhand der Koordinaten des Mittelpunktes, des Startpunktes und des Endpunktes UNABHÄNGIG vom Winkel. Deswegen hilft mir das oben nicht viel weiter.

Wie schaff ich es also einen Kreisbogen NUR aus den Koordinaten

M(m1|m2) Mittelpunkt
S(x1|y1) Startpunkt
E(x2|y2) Endpunkt

zu zeichnen?

Der Radius des Bogens berechnet sich wie folgt

r = Sqrt(Sqr(m1-x1)+Sqr(m2-y1))

Wer kann mir da weiterhelfen. Im Voraus schon einmal Danke.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 21.01.07 20:46 
muss denn der zweite punkt auf dem kreis liegen ? sonst lässt du den kreis da enden wo die gerade die durch M und P2 geht geschnitten wird.

mfg
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 21.01.07 21:55 
@Sors:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure MyArc(Canvas: TCanvas; m1, m2, x1, y1, x2, y2: Integer);
var
 R: Integer;
begin
  R := Round(Sqrt(Sqr(m1-x1)+Sqr(m2-y1)));
  Canvas.Arc(m1-R, m2-R, m1+R, m2+R, x1, y1, x2, y2);
end;