Autor Beitrag
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Sa 09.07.05 16:47 
Hier mal ein kleiner Ansatz von mir der aber von Grundauf verkehrt ist :wink:

(Image1.Picture.Bitmap ist nur ein Pixel groß, also nur ein punkt!)
irgendwie drehen sich die punkte nur um die Formkoordinate 0,0.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure Draw(grat, breite, laenge, drehx, drehy: Integer);
begin
  Form1.Repaint;
  Form1.Canvas.Draw(round(cosinus(grat)*drehx)-round(sinus(grat)*drehy),round(sinus(grat)*drehx)+round(cosinus(grat)*drehy),Form1.Image1.Picture.Bitmap);
  Form1.Canvas.Draw(round(cosinus(grat)*drehx)-round(sinus(grat)*laenge),round(sinus(grat)*drehx)+round(cosinus(grat)*laenge),Form1.Image1.Picture.Bitmap);
  Form1.Canvas.Draw(round(cosinus(grat)*breite)-round(sinus(grat)*drehy),round(sinus(grat)*breite)+round(cosinus(grat)*drehy),Form1.Image1.Picture.Bitmap);
  Form1.Canvas.Draw(round(cosinus(grat)*breite)-round(sinus(grat)*laenge),round(sinus(grat)*breite)+round(cosinus(grat)*laenge),Form1.Image1.Picture.Bitmap);
end;


habt ihr mal eine Funktionierende Procedure für mich auf Lager, oder könnt ihr mir sagen was ich da falsch bedacht habe?

MfG
-=LE=-
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 09.07.05 17:17 
Bevor du drehst ziehst du einfach die Koordinate des Mittelpunktes ab. Nach der Drehung zählst du die wieder dazu.
SAiBOT Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Sa 09.07.05 17:24 
von was abzeihen :cry:, hier nochmal mein ganzer code:

ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
function sinus(angle: Real): Real;
begin
  result := sin(Pi*angle/180);
end;

function cosinus(angle: Real): Real;
begin
  result := cos(Pi*angle/180);
end;

procedure Draw(grat, breite, laenge, drehx, drehy: Integer);
begin
  Form1.Repaint;
  Form1.Canvas.MoveTo(round(cosinus(grat)*drehx)-round(sinus(grat)*drehy),round(sinus(grat)*drehx)+round(cosinus(grat)*drehy));
  Form1.Canvas.LineTo(round(cosinus(grat)*drehx)-round(sinus(grat)*laenge),round(sinus(grat)*drehx)+round(cosinus(grat)*laenge));
  Form1.Canvas.LineTo(round(cosinus(grat)*breite)-round(sinus(grat)*laenge),round(sinus(grat)*breite)+round(cosinus(grat)*laenge));
  Form1.Canvas.LineTo(round(cosinus(grat)*breite)-round(sinus(grat)*drehy),round(sinus(grat)*breite)+round(cosinus(grat)*drehy));
  Form1.Canvas.LineTo(round(cosinus(grat)*drehx)-round(sinus(grat)*drehy),round(sinus(grat)*drehx)+round(cosinus(grat)*drehy));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.DoubleBuffered := True;
  Scrollbar1.Min := 0;
  Scrollbar1.Max := 360;
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  Draw(Scrollbar1.Position, 0, 0, 100, 100);
end;
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 09.07.05 17:35 
Gemäss deinem Titel möchtest du ja ein gedrehtes Rechteck zeichnen. Das kannst du mit dieser Prozedur:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure DrawRectangle(Canvas: TCanvas; Width, Height, CenterX, CenterY: Integer; Angle: Extended);
var
 sinA, cosA: Extended;
begin
   sinA := sin(Angle*pi/180);
   cosA := cos(Angle*pi/180);
   Canvas.Polygon([Point(CenterX+Round(width/2*cosA-height/2*sinA),
                         CenterY+Round(width/2*sinA+height/2*cosA)),
                   Point(CenterX+Round(-width/2*cosA-height/2*sinA),
                         CenterY+Round(-width/2*sinA+height/2*cosA)),
                   Point(CenterX+Round(-width/2*cosA+height/2*sinA),
                         CenterY+Round(-width/2*sinA-height/2*cosA)),
                   Point(CenterX+Round(width/2*cosA+height/2*sinA),
                         CenterY+Round(width/2*sinA-height/2*cosA))]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DrawRectangle(Image1.Canvas, 100,50, 100,100, 20);
end;
SAiBOT Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Sa 09.07.05 17:45 
rofl was optimiert THX
ManuelGS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 173

Win XP HE, Suse Linux
D6, D7, D2005 Personal
BeitragVerfasst: Sa 09.07.05 19:03 
sincos (math einbinden!) wäre doppelt so schnell wie sin und dann cos
siehe delphi-hilfe.
außerdem gibt es fkt. wie radtodeg, die das 180/p-zeug für einen machen...
aber ist eh korrinthenkackerei.

_________________
"Leben ist gänzlich Bühne und Spiel; so lerne denn spielen
und entsage dem Ernst - oder erdulde das Leid." - Palladas von Alexandria
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 09.07.05 22:07 
@Manuel: Die Routine von delfiphan kann noch um einiges Optimiert werden.

Z.B. Width/2 und Height/2 nicht ständig neu Berechnen.

Die von Dir genannte Routine ist dann nur eine Kleinigkeit.
Außerdem könnte er die Drehungsoffsets anhand der Punkt-Spiegelung realisieren.

D.h. In dieser Routine könnte man die Hälfte der Berechnungen wegoptimieren.

Zu erwartender Geschwindigkeitszuwachs: x4++

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 09.07.05 22:29 
Okay, ich versuch meistens möglichst optimale Routinen zu posten.

Aber hier lohnt es sich wohl kaum; vor allem hatte ich keine Lust, noch 4 oder 6 zusätzliche Variablen zu deklarieren. Das bringt's für einen DF-Post nicht; macht die Sache nur unnötig kompliziert.

Und für die, die's genau wissen wollen: Bei der Berechnung spart man ca. 21% (hab's ausprobiert). Der Flaschenhals ist aber ganz klar die Canvas-Operation. Die dauert fast 30 mal länger als die Berechnung. Aufs ganze gesehen macht die Optimierung also 0.7% aus.

@"*pi/180". Ich habe in meinen Codes nie Grad von 0..360 drin (Ausnahme OpenGl). 0..360 ist eine willkürliche Abmachung, historisch/didaktisch/praktisch bedingt. Ich hab das *pi/180 nur kurz hingemacht, weil man sonst erfahrungsgemäss die Antwort "es funktioniert nicht" kriegt. Hätt ich DegToRad() benützt, hätt ich zusätzlich noch erklären müssen, dass man die Math-Unit usen muss; usw.. Dasselbe gilt für sincos().