Autor Beitrag
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: Di 01.04.08 17:29 
hi,

Ich habe momentan das Problem, dass ich Pitch und Roll Werte aus einer 4x4 Matrix bestimmen muss. (Suche in: Delphi-Forum, Delphi-Library NEWTON -> NewtonBodyGetMatrix)

Mein bisheriger Versuch sieht so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
    NewtonBodyGetMatrix(NewtonBox[0].NewtonBody, @Matrix2[00]);
    m00 := Matrix2[00];
    m10 := Matrix2[10];
    m20 := Matrix2[20];
    m21 := Matrix2[21];
    m22 := Matrix2[22];
    beta := atan2(-m20, sqrt(m00 * m00 + m10 * m10));
    alpha := atan2(m10 / cos(beta), m00 / cos(beta));
    gamma := atan2(m21 / cos(beta), m22 / cos(beta));

Allerdings scheint dies nicht zu stimmen, wo liegt mein Fehler ?

mfg


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Di 01.04.2008 um 23:45
CarpeDiem
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 128

WIN XP
Borland C++ 2002, CodeGear C++ 2007, C# (VS 2008)
BeitragVerfasst: Di 01.04.08 18:21 
Hallo, ich habe diesen Quelltext nur bei files.codes-sources....f=SGL%5CSGL_Type.pas kopiert, vielleicht hilft er Dir ja weiter.

Für die Roll-Werte:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function MakeRollMatrix(Angle : Single) : TMatrix;
var
CA : Single;
SA : Single;
M : TMatrix;
begin
SA := Sin(Angle);
CA := Cos(Angle);
M[0,0] := CA; M[1,0] := SA; M[2,0] := 0; M[3,0] := 0;
M[0,1] := -SA; M[1,1] := CA; M[2,1] := 0; M[3,1] := 0;
M[0,2] := 0; M[1,2] := 0; M[2,2] := 1; M[3,2] := 0;
M[0,3] := 0; M[1,3] := 0; M[2,3] := 0; M[3,3] := 1;
Result := M;
end;

Für die Pitch-Werte:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function MakePitchMatrix(Angle : Single) : TMatrix;
var
CA : Single;
SA : Single;
M : TMatrix;
begin
SA := Sin(Angle);
CA := Cos(Angle);
M[0,0] := 1; M[1,0] := 0; M[2,0] := 0; M[3,0] := 0;
M[0,1] := 0; M[1,1] := CA; M[2,1] := SA; M[3,1] := 0;
M[0,2] := 0; M[1,2] := -SA; M[2,2] := CA; M[3,2] := 0;
M[0,3] := 0; M[1,3] := 0; M[2,3] := 0; M[3,3] := 1;
Result := M;
end;

Stefan

_________________
Stefan - Carpe Diem
Es ist keine Schande zu fallen, eine Schande ist nur nicht wieder aufzustehen
F34r0fTh3D4rk Threadstarter
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: Di 01.04.08 18:38 
hi,
danke, aber diesen Quelltext nutze ich selbst, nur brauche ich die Umkehrung dazu und dass scheint so nicht zu klappen.

mfg
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mi 02.04.08 15:30 
Die Indizierung in Stefans Code scheint genau umgekehrt zu der mathematisch üblichen. Deine Formeln sehen mir aber richtig aus, für eine homogene Transformation von Welt- zu Objektkoordinaten. Versuch doch einfach mal die Indizes auszutauschen, vermutlich wird das schon das Problem lösen.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
F34r0fTh3D4rk Threadstarter
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: Mi 02.04.08 16:29 
Das habe ich schon probiert, scheint aber auch nicht zu stimmen. Vielleicht ein Vorzeichenproblem ? In der Mathematik gibt es normalerweise nämlich keine negativen Grad Winkel, bei mir schon.

EDIT: scheint doch zu funktionieren, dann muss mein Problem woanders liegen.

mfg
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mi 02.04.08 17:36 
user profile iconF34r0fTh3D4rk hat folgendes geschrieben:
In der Mathematik gibt es normalerweise nämlich keine negativen Grad Winkel, bei mir schon.
Der Arkustangens liefert, wie der Arkussinus auch, Werte zwischen -pi/2 und pi/2 zurück, weil die Umkehrfunktionen beide pi-periodisch sind und punktsymmetrisch zum Ursprung verlaufen. Nur der Arkuskosinus hat einen Wertebereich von 0 bis pi. Ich frage mich daher, wie du auf die IDee kommst, daß negative Winkel in der Mathematik nicht vorkommen. Da du atan2() verwendest, kriegst du sogar auf dem Intervall -pi bis pi Werte, da der Arkustangens korrekt den Quadranten bestimmt, in dem der Winkel liegt. Beim Normalen Arkustangens kannst du beispielsweise nicht zwischen pi/4 und -3/4pi (entspricht 5/4pi) unterscheiden, atan2() kann das.
Wenn du aus deinen Werten im Bereich -pi bis pi Werte im Bereich pi bis 2pi haben willst, um sie über einen Bogen am Einheitskreis aufzutragen, musst du einfach nur alle negativen Werte von 2pi abziehen.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert