Autor Beitrag
Lomster
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Do 17.06.04 08:49 
HI ich hab ein Problem mit der graphischen Ausgabe.Wie sag ich Delphi wenn ich nen Punkt vorgegeben hab und Radius,Winkel und Seitenlänge bekannt sind,dass er Kreisförmig weitergehen soll und dort den nächsten Punkt zu zeichnen.Ist ja eigentliuch ganz einfach mathematisch,aber wie komm ich auf die Koordinaten vom Kreismittelpunkt?!

mfg Christian

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:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, StdCtrls;

type
  TVieleck = class
  private
    FKantenlaenge: real;
    FRadius: real;
    FAlpha: real;
    FEckenanzahl: integer;
    procedure SetEckenanzahl(const Value: integer);
    procedure SetKantenlaenge(const Value: real);
  public
    property Kantenlaenge: real read FKantenlaenge write FKantenlaenge;
    property Eckenanzahl: integer read FEckenanzahl write FEckenanzahl;
    procedure Calc;
    function Flaeche: real;
    procedure Paint(Canvas: TCanvas);
    constructor Create;
  end;


  TForm1 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label4: TLabel;
    PaintBox1: TPaintBox;
    SpeedButton1: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    Vieleck: TVieleck;
  end;

var
  Form1: TForm1;

implementation

uses Math;

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  if StrToInt(Edit1.Text) < 5 then Edit1.Text:= '5';
  if StrToFloat(Edit2.Text) <= 0 then Edit2.Text:= '1';

  Vieleck.Kantenlaenge:= StrToFloat(Edit2.Text);
  Vieleck.Eckenanzahl:= StrToInt(Edit1.Text);
  Vieleck.Calc;

  Vieleck.Paint(PaintBox1.Canvas);

  Label4.Caption:= FloatToStr(Vieleck.Flaeche);
end;

{ TVieleck }

procedure TVieleck.Calc;
begin
  falpha:= 360/FEckenanzahl;
  Fradius:= ((FKantenlaenge*sin((180-falpha)/2))/sin(falpha));
end;

constructor TVieleck.Create;
begin
  FEckenanzahl:= 5;
  FKantenlaenge:= 1;
end;

function TVieleck.Flaeche: real;
begin
  Result:= FEckenanzahl/2*sqr(FRadius)*abs(sin(falpha));
end;

procedure TVieleck.Paint(Canvas: TCanvas);
var
  sx,sy: integer;
  n: integer;
  alpha: real;
begin
  sx:= 100+round(fradius);
  sy:= 100+round(fradius);

  Canvas.MoveTo(round(sx+fradius),sy);
  for n:= 0 to FEckenanzahl+1 do
  begin
    alpha:= (n*FAlpha)*pi/180;
    Canvas.LineTo(round(sx+cos(alpha)*fradius),
                  round(sy+sin(alpha)*fradius));
  end;

end;

procedure TVieleck.SetEckenanzahl(const Value: integer);
begin
  FEckenanzahl := Value;
end;

procedure TVieleck.SetKantenlaenge(const Value: real);
begin
  FKantenlaenge := Value;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Vieleck:= TVieleck.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Vieleck.Free;
end;

end.
Neron17
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39

Win XP
D6 Prof
BeitragVerfasst: Mo 21.06.04 08:53 
Hej Lomster

Deine Beschreibung könnte etwas genauer sein.
So wie ich das bisher verstehe, willst du einen Punkt um einen unbekannten Mittelpunkt rotieren. Also Winkel und Punkt reichen da nciht aus, du brauchst schon den MP. Jetzt fragt sich natürlich, was die Seitenlänge ist (?).

MfG
Rico

P.S. Codedokumentation wäre mal ne Maßnahme