![]() |
Winkel in Position Umrechnung in 3D
Morgen.
Ich hab grad ein mathematisches Problem. Ich habe einen Körper, der sich im Radius d um den Mittelpunkt (0|0|0) drehen soll. Das Ding soll im Winkel roll zur z-Achse stehen und im Winkel turn zur y-Achse. Ich habe das Ding momentan nur so implementiert: x:=sinus(turn); y:=cosinus(turn); Wie integriere ich jetzt das mit roll? |
Re: Winkel in Position Umrechnung in 3D
Das ganze sollte mit
![]() Ansonsten koennte der haendische Weg so laufen:
Code:
Wenn ich mich nicht ganz taeusche...
//Rotation um Y
x' = cos(yaw) z = sin(yaw) //Rotation um Z x = cos(roll) y = sin(roll) * x' pos = (x, y, z) * d greetz Mike |
Re: Winkel in Position Umrechnung in 3D
Liste der Anhänge anzeigen (Anzahl: 1)
Ich hab mal den Code im Anhang geschrieben, der jedoch ziemlichen Mist produziert:
(Es muss GLScene installiert sein) |
Re: Winkel in Position Umrechnung in 3D
*push*
|
Re: Winkel in Position Umrechnung in 3D
Hier mal aus meiner 3D-Mathe-Unit alle Funktionen, die du dafür brauchst:
Delphi-Quellcode:
TVector3 = record
x, y, z: Single; end;
Delphi-Quellcode:
class function Vector.TransformCoords(const v: TVector3;
const M: TMatrix4; pfOutW: PSingle = nil): TVector3; var w: Single; begin with Result do begin x := v.x * M.m11 + v.y * M.m21 + v.z * m.m31 + m.m41; y := v.x * M.m12 + v.y * M.m22 + v.z * m.m32 + m.m42; z := v.x * M.m13 + v.y * M.m23 + v.z * m.m33 + m.m43; end; w := v.x * M.m14 + v.y * M.m24 + v.z * M.m34 + M.m44; if w <> 1 then begin with Result do begin x := x / w; y := y / w; z := z / w; end; end; if pfOutW <> nil then pfOutW^ := w; end;
Delphi-Quellcode:
TMatrix4 = record
m11, m12, m13, m14: Single; m21, m22, m23, m24: Single; m31, m32, m33, m34: Single; m41, m42, m43, m44: Single; end;
Delphi-Quellcode:
class function Matrix.RotationAxis(const v: TVector3; const f: Single): TMatrix4;
var fSin, fCos: Single; vAxis: TVector3; begin fSin := sin(-f); fCos := cos(-f); vAxis := Vector.Normalize(v); with Result do begin m11 := (vAxis.x * vAxis.x) * (1.0 - fCos) + fCos; m12 := (vAxis.x * vAxis.y) * (1.0 - fCos) - (vAxis.z * fSin); m13 := (vAxis.x * vAxis.z) * (1.0 - fCos) + (vAxis.y * fSin); m14 := 0; m21 := (vAxis.y * vAxis.x) * (1.0 - fCos) + (vAxis.z * fSin); m22 := (vAxis.y * vAxis.y) * (1.0 - fCos) + fCos; m23 := (vAxis.y * vAxis.z) * (1.0 - fCos) - (vAxis.x * fSin); m24 := 0; m31 := (vAxis.z * vAxis.x) * (1.0 - fCos) - (vAxis.y * fSin); m32 := (vAxis.z * vAxis.y) * (1.0 - fCos) + (vAxis.x * fSin); m33 := (vAxis.z * vAxis.z) * (1.0 - fCos) + fCos; m34 := 0; m41 := 0; m42 := 0; m43 := 0; m44 := 1; end; end; Und hier ein Beispiel, wie du deine Drehung berechnen würdest:
Delphi-Quellcode:
var
vPoint: TVector3; M: TMatrix4; begin // Ortsvektor, der sich an den Koordinaten (5|0|0) befindet vPoint.x := 5; vPoint.y := 0; vPoint.z := 0; // Drehmatrix, die eine Drehung um die z-Achse um 90° durchführt M := Matrix.RotationAxis(Vector.Make(0, 0, 1), pi/2); // Punkt mit der Drehmatrix transformieren vPoint := Vector.TransformCoords(vPoint, M); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz