Autor Beitrag
delphisual
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

WIN 2000
D5 Prof
BeitragVerfasst: So 19.10.03 15:08 
Hallo zusammen,

ich habe ein Problem und zwar möchte ich eine Ellipse im bestimmten Winkel zeichnen wenn ich aber die Parameter x1,y1,x2,y2 angebe wird die Ellipse immer parallel zu meiner Zeichenfläche gezeichnet! Kennt jemand eine Möglichkeit wie ich das übergehen kann? :roll:

danke schon mal
delphisual

_________________
(Wer ein Problem definiert, hat es schon halb gelöst.)
Sven
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314


D6 Ent, K3 Pro (patched)
BeitragVerfasst: Mo 20.10.03 11:46 
Es bietet sich folgende Lösung an. Mit dieser Funktion kannst Du auch Ellipsen erstellen, die nicht vollständig geschlossen sind.

ausblenden volle Höhe 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:
61:
62:
63:
64:
65:
66:
67:
Type TFPoint = record
       x, y : double;
     end;

...

procedure DrawEllipse(xfp: array of TFPoint);
  var j, estep,
      xRot, yRot               : integer;
      cm, p1, p2               : TPoint;
      p3f, p4f, p5f, theta,
      aWinkel, bWinkel,
      RAngle, r1, r2           : double;
      allPt                    : array [0..361] of TPoint;
begin
  try
    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) );
    allPt[0] := Point(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) );
      allPt[j] := Point(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) );
    allPt[eStep+1] := Point(xRot, yRot);
    ?.Canvas.Start(true);
    ?.Canvas.Polyline(allPt, 0, eStep+1);
    ?.Canvas.Stop;
  except
    //...
  end;
end; {DrawEllipse}


In dem Array haben die Punkte folgende Bedeutung:
- Mittelpunkt der Ellipse
- Punkt um den Radius der Hauptachse zu bestimmen.
Hierdurch wird auch der Winkel der Ellipse festgelegt.
- Verhältnis zwischen Hauptachse und Nebenachse (nur X-Wert)
- Anfangswinkel (nur X-Wert)
- endwinkel (nur X-Wert)

Das ? bitte durch das ersetzen, worauf du zeichnen willst.

Sven

_________________
MDK 9.1, Kernel 2.4.21, KDE 3.1 Kylix 3 Pro (patched), nutze aber auch Windows
delphisual Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

WIN 2000
D5 Prof
BeitragVerfasst: Mo 20.10.03 12:49 
Hei Sven und danke für dein Posting!

ich bin gerade dabei die Procedure DrawEllipse durchzukauen, es fehlen mir aber die angaben über die function CnvToP auch Winkel, Radius, isZero Start und Stop findet mein Compiler nicht! Muss ich eine bestimmte Unit dafür haben?

Mit freundlichen Grüßen
delphisual

_________________
(Wer ein Problem definiert, hat es schon halb gelöst.)
Sven
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314


D6 Ent, K3 Pro (patched)
BeitragVerfasst: Mo 20.10.03 17:16 
Sorry, CnvToP ist eine Funktion, die die Double-Werte der ersten beiden Punkte in Pixel umrechnet. DrawEllipse stammt aus meinem CAD-Programm.
Du kannst natürlich auch die beiden ersten Paramter als TPoint übergeben.
Winkel und Radius sind Funktionen entsprechend ihrem Namen.
isZero ist in der Unit Math deklariert, also einfach Math einbinden.
Start und Stop kannst Du streichen, da ich das Programm mit CLX entwickelt habe. Unter VCL gibt es die nicht.

Gruß Sven

_________________
MDK 9.1, Kernel 2.4.21, KDE 3.1 Kylix 3 Pro (patched), nutze aber auch Windows
delphisual Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 89

WIN 2000
D5 Prof
BeitragVerfasst: Di 21.10.03 18:42 
Danke Sven für deine Mühe ich versuche es umzusetzen.

_________________
(Wer ein Problem definiert, hat es schon halb gelöst.)