AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Winkel in Position Umrechnung in 3D
Thema durchsuchen
Ansicht
Themen-Optionen

Winkel in Position Umrechnung in 3D

Ein Thema von 3_of_8 · begonnen am 21. Aug 2006 · letzter Beitrag vom 22. Aug 2006
Antwort Antwort
Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#1

Winkel in Position Umrechnung in 3D

  Alt 21. Aug 2006, 13:10
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?
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat
Benutzerbild von JasonDX
JasonDX
(CodeLib-Manager)

Registriert seit: 5. Aug 2004
Ort: München
1.062 Beiträge
 
#2

Re: Winkel in Position Umrechnung in 3D

  Alt 21. Aug 2006, 13:26
Das ganze sollte mit Rotationsmatrizen zu loesen sein
Ansonsten koennte der haendische Weg so laufen:
Code:
//Rotation um Y
x' = cos(yaw)
z = sin(yaw)
//Rotation um Z
x = cos(roll)
y = sin(roll) * x'
pos = (x, y, z) * d
Wenn ich mich nicht ganz taeusche...

greetz
Mike
Mike
Passion is no replacement for reason
  Mit Zitat antworten Zitat
Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#3

Re: Winkel in Position Umrechnung in 3D

  Alt 21. Aug 2006, 17:40
Ich hab mal den Code im Anhang geschrieben, der jedoch ziemlichen Mist produziert:

(Es muss GLScene installiert sein)
Angehängte Dateien
Dateityp: zip atomicstructure_227.zip (2,3 KB, 8x aufgerufen)
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat
Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#4

Re: Winkel in Position Umrechnung in 3D

  Alt 22. Aug 2006, 18:18
*push*
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat
Oxmyx

Registriert seit: 21. Sep 2004
499 Beiträge
 
#5

Re: Winkel in Position Umrechnung in 3D

  Alt 22. Aug 2006, 19:43
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;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz