Autor Beitrag
mtin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Do 13.04.06 01:08 
tja, also ich habe einen Punkt im Zentrum und um diesen herum einige beliebige Punkte(in nem array)
Diese möchte ich nun sortieren, also sozusagen im "uhrzeigersinn" (oder auch dagegen, spielt keine Rolle)...dafür muss ich zunächst einmal die Winkel der jeweiligen Strecken (immer vom Zentrum zu einem der darumliegenden Punkte) berechnen....wie stell ich das denn am dümmsten an?
hab mir jetzt folgendes geschrieben, das will aber einfach nicht funktionieren...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
function winkel(p1,p2:TPolygonPunkt):real;
begin
if p1.x>p2.x then
  begin
  if p1.y>p2.y then
    Result:=arctan((p1.y-p2.y)/(p1.x-p2.x));
  else
//if p1.y<p2.y then
    Result:=arctan((p1.x-p2.x)/(p2.y-p1.y))+(3.14159265/2)*3;
  end
else
//if p1.x<p2.x then
  begin
  if p1.y>p2.y then
    Result:=arctan((p2.x-p1.x)/(p1.y-p2.y))+(3.14159265/2);
  else
//if p1.y<p2.y then
    Result:=arctan((p2.y-p1.y)/(p2.x-p1.x))+3.14159265;
  end;
end;

dabei hab ich zunächst mal eine Fallunterscheidung vorgenommen, in welchem Quadranten denn der äußere Punkt liegt und dann den Winkel zu einm Fixpunkt berechnet...bzw. das wollte ich^^

hier nochmal eine kleine skizze:
user defined image
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 13.04.06 07:06 
nimm statt arctan mal aus der unit Math arctan2!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
zemy
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 207

Win XP Prof.
D7
BeitragVerfasst: Do 13.04.06 09:39 
Zur Erklärung, warum arctan2:
Wenn du im 3. Quadrantren bist, sind ja die x und die y-Koordinaten negativ. - * - = +... schlecht:( Genauso wenn du im 2. oder 4. Quadranten bist... beides negativ. arctan2 übernimmt für dich die Fallunterscheidungen. Das einzigste, was du noch machen musst, ist 2*Pi drauf zu addieren, wenn der zurückgegebene Winkel negativ ist (Der Winkel wird im mathematisch-positiven Sinn zur x-Achse angegeben)

MfG

_________________
LifeIsToShortToThinkAboutTheShortness
mtin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 177

Win XP SP2
BDS2006 Enterprise
BeitragVerfasst: Do 13.04.06 11:56 
öhm, könntest du mir das vielleicht bitte noch ein wenig genauer erklären?
wann soll ich was addiren, und warum will ArcTan2 plötzlich 2 parameter???
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Do 13.04.06 12:02 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function Winkel360(Mittelpunkt: TPoint; EndPunkt: TPoint): extended;
var
y, x: integer;
begin
if (Mittelpunkt.X = EndPunkt.X) and (Mittelpunkt.Y = EndPunkt.Y) then
  begin
  result := -1;
  exit;
  end;
x := Mittelpunkt.X - EndPunkt.X;
y := Mittelpunkt.Y - EndPunkt.Y;
result := RadToDeg(arctan2(y, x));  //"Delphi-Winkel" ohne Bogenmaß
result := result + 270;  //Skala um 270° drehen
if result >= 360 then  //alte positive Winkel in neues Format bringen
  result := result - 360;
end;
Ist meine lösung dazu. Es berechnet den winkel im urzeigersinn 0 - 360°


mfg