Autor Beitrag
IhopeonlyReader
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 600
Erhaltene Danke: 23


Delphi 7 PE
BeitragVerfasst: Di 02.04.13 16:53 
Guten Tag,
ich hatte schon einmal ein ähnliches Thema: www.entwickler-ecke....topic.php?t=111045...
Ich würde gerne ein 3D- Viereck (mit komplett gleichen Seitenlängen hoehe, breite, tiefe) drehen können..

die procedure soll folgendermaßen aufgerufen werden: ZeichneEs(50, 60, Form1.Canvas)
Es soll also um 50° nach Links gedreht werden und um 60° nach oben...
Ich will eigentlich jetz nur wissen, wie man das Verhältnis der Seitenlängen berechen kann, und wie die gesamte (zusehende) Breite ist

Also:
Bei der Kantenlänge: 4 (gehen wir immer von (90x)° senkrechter Drehung aus)
ist bei 0° waagerechter Drehung die gesamtBreite 4cm, die hoehe 4 und seite1 4, seite 0 (links von seite1) 0 und seite 2 (rechts von seite 1) 0
bei 45° waagerechter Drehung die gesamteBreite ca 5,66 (((4^(2)+4^(2))^(0.5)) Verhältnis von Seite 1 zu Seite 2 ist 1:1 (beide Seiten sind (32^(0.5))/2 (ca 2.83) lang. aber wie ist das bei 22,5° Drehung in der waagerechten? ich weiß dass Verhältnis von 22,5° Drehung genau 1/(Verhältnis 360-22,5°) ist... Aber wie groß genau?
Ebenfalls weiß ich, dass das Viereck sich auf einer Kreisbahn bewegt, in der der Radius = (2*(KantenLänge^2))^0.5 ist...

_________________
Sucht "neueres" Delphi :D
Wer nicht brauch was er hat, brauch auch nicht was er nicht hat!
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 02.04.13 18:37 
mit einem 3D Viereck meinst Du einen Würfel?
Hier gibt es was zum spicken www.efg2.com/Lab/Graphics/ThreeDLab.htm

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
IhopeonlyReader Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 600
Erhaltene Danke: 23


Delphi 7 PE
BeitragVerfasst: Di 02.04.13 19:12 
Gesamte Breite habe ich nun herausgefunden ist gleich
ca 5.23 bei einer kantenlänge von 4 und einer Rotation von 22.5°

Nun muss ich nur noch das Verhältnis bestimmem :).... Falls wer ähnliche Probleme hat und einen Rechenweg brauch dann schreib ich ihn wohl gern dazu^^

Edit: Bummis Eintrag jetzt erst bemerkt :D Danke :) aber was genau ist das? extra Objekte?

Moderiert von user profile iconNarses: Beiträge zusammengefasst

Und wenn mich nicht alles Täuscht dann ist das Seitenverhältis nichts anderes als das Verhältnis des Rotationswinkels zu einem kompletten Seitenwechsel (Drehung bis zu nächsten Seite)

also rw/90 und (90-rw)/90... dreht man nach links ist das Verhältnis rw/90 zu 1 bzw. 1 zu (90-rw)/90
dreht man nach rechts ist das Verhältnis 1 zu rw/90 bzw. das andere... :D zu einfach^^.. aber bummi was ist das denn was du gepostet hast?

_________________
Sucht "neueres" Delphi :D
Wer nicht brauch was er hat, brauch auch nicht was er nicht hat!
MeierZwoo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 94
Erhaltene Danke: 11

Win 7, DOS5
Delphi 2007 Architect, BP7/TP5, LISP, PS
BeitragVerfasst: Mi 03.04.13 10:24 
user profile iconIhopeonlyReader hat folgendes geschrieben Zum zitierten Posting springen:

Ich würde gerne ein 3D- Viereck (mit komplett gleichen Seitenlängen hoehe, breite, tiefe) drehen können..


mmmh, ein "3D-Viereck" wäre eine Dreiecks-Pyramide, nur hat eine Dreiecks-Pyramide eine andere Tiefe und Höhe als Seiten(Kanten)länge!
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Mi 03.04.13 11:18 
Moin,

meiner Meinung nach gibt es nicht besonders viele Möglichkeiten, das vernünftig zu machen. Entweder man nutzt direkt etwas wie OpenGL, oder man setzt sich zehn Minuten mit Dreh- und Projektionsmatrizen auseinander.

Wenn man jetzt gar keine Matrizen benutzen möchte (ich weise darauf hin: Es ist nicht beliebig schwierig. Es gibt dazu bestimmt auch etwas Fertiges.), dann sollte man doch zumindest Vektoren benutzen und diese Drehen(Sinus, Cosinus) bzw. projizieren (Projektionsmatrix auf v: Q = (v^T*v)/(v*v^T) bzw. Skalarprodukt: Projektion von v auf w = P_w(v) =  <v,w>/||w|| * v).

Gruß
jfheins
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Mi 03.04.13 11:59 
Vielleicht hilft dir dieser Thread aus er DP weiter: www.delphipraxis.net...beliebige-achse.html

Was damals noch nicht so gut geklappt hat ist die "Zentralprojektion", das sieht zwar ein bisschen so aus, ist aber Murks. Solange du nur Parallelprojektion brauchst ist der Code problemlos einzusetzen. Falls du mit dem C# Code nicht zurecht kommst, frag' einfach. Der Großteil sollte aber verständlich sein, insbesondere die Mathematischen Gleichungen.
IhopeonlyReader Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 600
Erhaltene Danke: 23


Delphi 7 PE
BeitragVerfasst: Mi 03.04.13 13:26 
ich habe mir jetzt eine eigene Routine verfasst, die ein Würfel dreht !
es klappt alles :D war halt nur viel "Herleitung" insgesamt sind es 4 Formeln und bisschen schummellei^^ (z.B. wenn drehwinkel > 90 dann drehwinkel -90 und seite +1)..

aber danke für die Hilfe :D

_________________
Sucht "neueres" Delphi :D
Wer nicht brauch was er hat, brauch auch nicht was er nicht hat!
MeierZwoo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 94
Erhaltene Danke: 11

Win 7, DOS5
Delphi 2007 Architect, BP7/TP5, LISP, PS
BeitragVerfasst: Mi 03.04.13 17:47 
user profile iconIhopeonlyReader hat folgendes geschrieben Zum zitierten Posting springen:
ich habe mir jetzt eine eigene Routine verfasst, die ein Würfel dreht


Nun plötzlich ein Würfel? Ein Würfel hat aber acht Ecken, keine vier!
IhopeonlyReader Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 600
Erhaltene Danke: 23


Delphi 7 PE
BeitragVerfasst: Do 04.04.13 12:47 
Naja von der Formel ist es aber dasselbe ?! nur dass ich bei nem würfel sozusagen 6 Vierecke bewege...

_________________
Sucht "neueres" Delphi :D
Wer nicht brauch was er hat, brauch auch nicht was er nicht hat!
IhopeonlyReader Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 600
Erhaltene Danke: 23


Delphi 7 PE
BeitragVerfasst: Do 04.04.13 12:59 
Für alle die es mal sehen wollen habe ich im Anhang ein Projekt, in dem ich einen Würfel rotieren lasse.
Damit Man alle Seiten sieht, ist der Würfel "durchsichtig" und der würfel wurde links 10% höher gesetzt als auf der rechten seite..
(durch die "hochsetzung" sind natürlich die nach oben gehenden seiten leicht schräg und damit länger, aber dies dient auch nur zur Vereinfachung der Erkennung :D)
Einloggen, um Attachments anzusehen!
_________________
Sucht "neueres" Delphi :D
Wer nicht brauch was er hat, brauch auch nicht was er nicht hat!
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Fr 05.04.13 02:23 
Hey,

das ist aber nicht wirklich ein Würfel. Wenn man den auf 0° oder 180° dreht, dann ist er verzerrt...
Ich hatte das damals in nem anderen Thread mit Matricen gemacht. So wie FinnO das schon erwähnt hatte. Die Matrizen sind zwar vom Verständnis her etwas schwieriger als ein einfacher sin/cos, aber dafür sind die sehr viel mächtiger und vorallem auch kürzer! Ich hab dir das Projekt von damals mal mit in den Anhang gepackt.

MfG Bergmann.

p.s.: der Würfel lässt sich mit den Pfeiltasten auch bewegen...
Einloggen, um Attachments anzusehen!
_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: So 07.04.13 10:48 
Kleiner tipp: Form.doublebuffered:=true hilft gegen das flimmern.
Fiete
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 601
Erhaltene Danke: 339

W7
Delphi 6 pro
BeitragVerfasst: So 07.04.13 17:48 
Moin,
hier ein Fundstück Anno 1995, könnte nützlich sein :wink:
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:
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:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
unit CubeRotate;
{***************************************************}
{* The 3D Rotating Cube - A Comprehensive example  *}
{* of using animation in Delphi. This application  *}
{* displays a rotating 3 dimensional cube. The user*}
{* can adjust how quickly the cube rotates on each *}
{* axis.                                           *}
{***************************************************}

interface

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

type
  TDrehen = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Timer: TTimer;
    ResetCube: TButton;
    XRot: TScrollBar;
    YRot: TScrollBar;
    ZRot: TScrollBar;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TimerTimer(Sender: TObject);
    procedure ResetCubeClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var Drehen: TDrehen;

implementation

{$R *.DFM}

Type
  {Used to create a rotation matrix}
  Matrix=array[0..3,0..3of Extended;
  {Structure to store a 3D point   }
  TDPoint=record X,Y,Z:Extended end;

var
  DoubleBuffer:TBitmap;  {We will draw here then copyrect}
  BlankBuffer:TBitmap;  {Bitmap to store our background }
  PntsOut:array[1..8of TDPoint; {Rotated Points}
  TPPnts:array[1..8of TPoint;  {2D represtentation of pts}
  Pnts:array[1..8of TDPoint;   {Origional image}
  XAng,YAng,ZAng:Extended;

{********************************************************}
{Create an array(or matrix) which sets up rotation based }
{on angels passed in terms or radians. Consult a geometry}
{book to understand the math behind rotation.            }
{********************************************************}
 procedure matrixRotate(var m:Matrix;x,y,z:Extended);
  var sinX,cosX,sinY,cosY,sinZ,cosZ:Extended; {Store here so we only need to calc once}
      C1,C2:integer; {for the loops}
  begin
   sinX := sin(x); {let's do our geometry...}
   cosX := cos(x);
   sinY := sin(y);
   cosY := cos(y);
   sinZ := sin(z);
   cosZ := cos(z);
   for C1 := 0 to 3 do  {set the matrix to the identity}
    for C2 :=0 to 3 do
     if C1 = C2 then M[C1,C2]:=0
     else M[C1,C2]:=1;
   {Take my word for it this works!....}
   M[0,0]:=cosZ*cosY;
   M[0,1]:=cosZ*-sinY*-sinX+sinZ*cosX;
   M[0,2]:=cosZ*-sinY*cosX+sinZ*sinX;
   M[1,0]:=-sinZ*cosY;
   M[1,1]:=-sinZ*-sinY*-sinX+cosZ*cosX;
   M[1,2]:=-sinZ*-sinY*cosX+cosZ*sinX;
   M[2,0]:=sinY;
   M[2,1]:=cosY*-sinX;
   M[2,2]:=cosY*cosX;
  end;

{Apply the rotation matrix to a 3D point and return a new 3D point}
 procedure ApplyMatToPoint(PointIn : TDPoint; var pointOut:TDPoint;mat : Matrix);
  var x,y,z:Extended;
  begin
   x:=PointIn.x*mat[0,0]+PointIn.y*mat[0,1]+PointIn.z*mat[0,2]+mat[0,3];
   y:=PointIn.x*mat[1,0]+PointIn.y*mat[1,1]+PointIn.z*mat[1,2]+mat[1,3];
   z:=PointIn.x*mat[2,0]+PointIn.y*mat[2,1]+PointIn.z*mat[2,2]+mat[2,3];
   PointOut.x:=x;PointOut.y:=y;PointOut.z:=z;
  end;

{We are using a cube which has 8 point. This is where we setup the }
{coordinates for each point. The middle of the cube is at (0,0,0)  }
 procedure InitCube;
  begin
   Pnts[1].X:=-50;Pnts[1].Y:=-50;Pnts[1].Z:=-50;
   Pnts[2].X:=50;Pnts[2].Y:=-50;Pnts[2].Z:=-50;
   Pnts[3].X:=50;Pnts[3].Y:=50;Pnts[3].Z:=-50;
   Pnts[4].X:=-50;Pnts[4].Y:=50;Pnts[4].Z:=-50;
   Pnts[5].X:=-50;Pnts[5].Y:=-50;Pnts[5].Z:=50;
   Pnts[6].X:=50;Pnts[6].Y:=-50;Pnts[6].Z:=50;
   Pnts[7].X:=50;Pnts[7].Y:=50;Pnts[7].Z:=50;
   Pnts[8].X:=-50;Pnts[8].Y:=50;Pnts[8].Z:=50;
  end;

{The following function returns true if the sum of the  }
{parameters is greater then zero and false if it is     }
{less then zero. We will use this function to determine }
{Which sides of the cube to hide and which to show      }
 function ShowSide(V1,V2,V3,V4:Extended):Boolean;
  begin
   if V1+V2+V3+V4>0 then ShowSide:=TRUE
   else ShowSide:=FALSE;
  end;

{We are using a double buffer. This function determines if a side}
{is visible. If it is, it draws the 2D representation on our     }
{bitmap buffer with the fill set to the color passed             }
 procedure AddSide(P1,P2,P3,P4:Integer;SideColor : TColor);
  begin
   if ShowSide(PntsOut[P1].Z,PntsOut[P2].Z,PntsOut[P3].Z,PntsOut[P4].Z) then
    begin
     DoubleBuffer.Canvas.Brush.Color:=SideColor;
     DoubleBuffer.Canvas.Polygon([TPPnts[P1],TPPnts[P2],TPPnts[P3],
                                  TPPnts[P4],TPPnts[P1]]);
    end;
  end;

{When the form loads, create and initialize our background bitmap}
{and initialize our double buffer bitmap.                        }
 procedure TDrehen.FormCreate(Sender: TObject);
  begin
   DoubleBuffer:=TBitmap.Create;
   DoubleBuffer.Height:=200;
   DoubleBuffer.Width:=200;
   BlankBuffer:=TBitmap.Create;
   BlankBuffer.Height:=200;
   BlankBuffer.Width:=200;
   BlankBuffer.Canvas.Brush.Color:=clWhite;
   BlankBuffer.Canvas.rectangle(0,0,200,200);
   InitCube;XAng:=0;YAng:=0;ZAng:=0;
  end;

{When we are done we need to clean up by freeing out bitmaps}
 procedure TDrehen.FormClose(Sender: TObject; var Action: TCloseAction);
  begin
   BlankBuffer.Free;
   DoubleBuffer.Free;
  end;

{The main procedure which draws the cube. This procedure is called  }
{by a timer that executes its OnTimer function every 20 milliseconds}
 procedure TDrehen.TimerTimer(Sender: TObject);
  var M:Matrix;             {The matrix used to rotate the cube}
      Count,Count2:Integer; {Used to loop through points       }
  begin
    XAng:=XAng+XRot.Position;  {adjust the rotation angle}
    YAng:=YAng+YRot.Position;  {by pulling out of the    }
    ZAng:=ZAng+ZRot.Position;  {scroll bars              }
    {Adjust for degrees and build the rotation matrix}
    matrixRotate(M,(PI*XAng)/180,(PI*YAng)/180,(PI*ZAng)/180);
    {Loop through all of the points and rotate, the get 2D representation}
    for Count2:=1 to 8 do
     begin
      ApplyMatToPoint(Pnts[Count2],PntsOut[Count2],M);
      TPPnts[Count2]:=Point(trunc(PntsOut[Count2].X+100),trunc(PntsOut[Count2].Y+100));
     end;
    {Clear the double buffer by copyrect[ing] the Background}
    DoubleBuffer.Canvas.CopyRect(RECT(0,0,200,200),BlankBuffer.Canvas,RECT(0,0,200,200));
    {Build the cube by calling AddSide for each of the 6 sides}
    AddSide(1,2,3,4,clBlue);
    AddSide(5,6,7,8,clRed);
    AddSide(1,2,6,5,clYellow);
    AddSide(2,3,7,6,clGreen);
    AddSide(3,4,8,7,clPurple);
    AddSide(4,1,5,8,clSilver);
    {Copy the double buffer to the form}
    Drehen.Canvas.CopyRect(RECT(0,0,200,200),DoubleBuffer.Canvas,RECT(0,0,200,200));
  end;

{To bring the cube back to its origional state, remove the rotation angles}
 procedure TDrehen.ResetCubeClick(Sender: TObject);
  begin
   XAng:=0;YAng:=0;ZAng:=0;
  end;

end.


Gruß Fiete
Einloggen, um Attachments anzusehen!
_________________
Fietes Gesetz: use your brain (THINK)