Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Rechtecksdrehung im Koordinatensystem

Empfohlene Antworten

Veröffentlicht

Ich arbeite an einem bauphysikalischen Programm zur Berechnung des Heizwärmebedarfs von Gebäuden. Das Hauptproblem liegt bei mir darin, dass in einer kleinen Vorschauskizze die rechteckige Grundfläche eines Hauses (a, B) im richtigen Verhältnis gezeichnet werden soll. Dadurch, dass ein Computerbildschirm in einzelne Bildpunkte geteilt ist, kann man sich das ganze als Kartesisches Koordinatensystem vorstellen. Die Vorschau mit einem normalen Rechteck funktioniert bereits jedoch habe ich ein Problem damit, dass man auch einen Winkel alpha festlegen kann, der die Abweichung des Grundstückes von Norden angibt, sprich das Rechteck soll im Koordinatensystem entsprechend dem Winkel alpha gedreht werden. Das Problem, dass ich jetzt habe, ist, dass ich nicht genau weiß wie ich die Koordinaten der Punkte (A, B, C, D) des gedrehten Rechteckes ermitteln kann. Ich habe zwar schon probiert, das Problem mit Vektoren bzw. Matrizen zu lösen, bis jetzt aber ohne Erfolg.

post-49924-14430447893623_thumb.jpg

post-49924-14430447893851_thumb.jpg

`$1...x1

`$2...y1

`$3...x2

`$4...y2

`$5...x3

`$6...y3

`$7...x4

`$8...y4

`$9...Winkelverschiebung um alpha(-180°-180°)

C_REAL($1;$2;$3;$4;$5;$6;$7;$8;$9)

C_REAL($x_1;$x_2;$x_3;$x_4;$y_1;$y_2;$y_3;$y_4)

`C_INTEGER($M_x;$M_y)

`C_INTEGER($x1;$x2;$x3;$x4;$y1;$y2;$y3;$y4)

C_REAL($alpha)

$alpha:=$9*Degree

If (($alpha=0) | ($9=180) | ($9=(-180)))

$x_1:=$1

$y_1:=$2

$x_2:=$3

$y_2:=$4

$x_3:=$5

$y_3:=$6

$x_4:=$7

$y_4:=$8

Else

If ($9<0)

$x_1:=$1*Cos($alpha)-$2*Sin($alpha)

$x_2:=$3*Cos($alpha)-$4*Sin($alpha)

$x_3:=$5*Cos($alpha)-$6*Sin($alpha)

$x_4:=$7*Cos($alpha)-$8*Sin($alpha)

$y_1:=$1*Sin($alpha)+$2*Cos($alpha)

$y_2:=$3*Sin($alpha)+$4*Cos($alpha)

$y_3:=$5*Sin($alpha)+$6*Cos($alpha)

$y_4:=$7*Sin($alpha)+$8*Cos($alpha)

Else

$alpha:=$alpha*(-1)

$x_1:=$1*Cos($alpha)-$2*Sin($alpha)

$x_2:=$3*Cos($alpha)-$4*Sin($alpha)

$x_3:=$5*Cos($alpha)-$6*Sin($alpha)

$x_4:=$7*Cos($alpha)-$8*Sin($alpha)

$y_1:=$1*Sin($alpha)+$2*Cos($alpha)

$y_2:=$3*Sin($alpha)+$4*Cos($alpha)

$y_3:=$5*Sin($alpha)+$6*Cos($alpha)

$y_4:=$7*Sin($alpha)+$8*Cos($alpha)

End if

End if

ARRAY INTEGER(koord;8)

koord{1}:=$x_1

koord{2}:=$y_1

koord{3}:=$x_2

koord{4}:=$y_2

koord{5}:=$x_3

koord{6}:=$y_3

koord{7}:=$x_4

koord{8}:=$y_4

$0:=koord

Das Problem ist aber, dass die Vorschau so aussieht:

post-49924-14430447893993_thumb.png

Matrix D =

| cos(alpha) sin(alpha)|

|-sin(alpha) cos(alpha)|

P_neu = D*P_alt

ergo:

x_neu = x_alt*cos(alpha)+y_alt*sin(alpha)

y_neu = -x_alt*sin(alpha)+y_alt*cos(alpha)

Vorzeichen verwechselt?

So, danke mal für die Antworten.

1. Habe jetzt das mit den Vorzeichen geändert, funktioniert leider doch nicht

2. Das mit der Unterscheidung muss noch gemacht werden, macht aber erst

Sinn wenn es auch so funktioniert

`$1...x1

`$2...y1

`$3...x2

`$4...y2

`$5...x3

`$6...y3

`$7...x4

`$8...y4

`$9...Winkelverschiebung um alpha(-180°-180°)

C_REAL($1;$2;$3;$4;$5;$6;$7;$8;$9)

C_REAL($x_1;$x_2;$x_3;$x_4;$y_1;$y_2;$y_3;$y_4)

`C_INTEGER($M_x;$M_y)

`C_INTEGER($x1;$x2;$x3;$x4;$y1;$y2;$y3;$y4)

C_REAL($alpha)

$alpha:=$9*Degree

If (($alpha=0) | ($9=180) | ($9=(-180)))

$x_1:=$1

$y_1:=$2

$x_2:=$3

$y_2:=$4

$x_3:=$5

$y_3:=$6

$x_4:=$7

$y_4:=$8

Else

If ($9<0)

$x_1:=$1*Cos($alpha)+$2*Sin($alpha)

$x_2:=$3*Cos($alpha)+$4*Sin($alpha)

$x_3:=$5*Cos($alpha)+$6*Sin($alpha)

$x_4:=$7*Cos($alpha)+$8*Sin($alpha)

$y_1:=-$1*Sin($alpha)+$2*Cos($alpha)

$y_2:=-$3*Sin($alpha)+$4*Cos($alpha)

$y_3:=-$5*Sin($alpha)+$6*Cos($alpha)

$y_4:=-$7*Sin($alpha)+$8*Cos($alpha)

Else

$alpha:=$alpha*(-1)

$x_1:=$1*Cos($alpha)+$2*Sin($alpha)

$x_2:=$3*Cos($alpha)+$4*Sin($alpha)

$x_3:=$5*Cos($alpha)+$6*Sin($alpha)

$x_4:=$7*Cos($alpha)+$8*Sin($alpha)

$y_1:=-$1*Sin($alpha)+$2*Cos($alpha)

$y_2:=-$3*Sin($alpha)+$4*Cos($alpha)

$y_3:=-$5*Sin($alpha)+$6*Cos($alpha)

$y_4:=-$7*Sin($alpha)+$8*Cos($alpha)

End if

End if

ARRAY INTEGER(koord;8)

koord{1}:=$x_1

koord{2}:=$y_1

koord{3}:=$x_2

koord{4}:=$y_2

koord{5}:=$x_3

koord{6}:=$y_3

koord{7}:=$x_4

koord{8}:=$y_4

$0:=koord

Und so sieht das ganze dann aus

[ATTACH]1811[/ATTACH]

Hallo,

@Stampi: Warum beschreibst Du die 4 Eckpunkte nicht als Vektoren, das macht vieles einfacher und vor allem kannst Du dann die Rotationsmatrix von TDM verwenden. Der ganze Code wäre dadurch etwas übersichtlicher und man könnte direkt sehen, wie was funktioniert. Implementiere doch mal die Gleichung

@TDM: so sähe Die Matrix bei mir auch aus.

Phil

2. Das mit der Unterscheidung muss noch gemacht werden, macht aber erst

Sinn wenn es auch so funktioniert

Nein.

Die Matrix gilt immer, auch wenn der Winkel negativ ist.

Ist dir nicht aufgefallen, dass der einzige Unterschied zwischen dem Code im if-Block und dem im else-Block der ist, dass du das Vorzeichen von alpha umdrehst? Das heißt, du machst bei -45° dasselbe wie bei +45°. Das kann's ja wohl nicht sein.

Ansonsten sieht die Rechnung gut aus. Bist du sicher, dass die Eingabedaten richtig verteilt sind und du die Ausgabedaten richtig interpretierst? Gib doch einfach mal die Werte aller Ein- und Ausgabevariablen mit an.

Das ist der Code, der das ganze zeichnet.

Die Funktion "PROJ_AssistentWinkelVersch" ist jener Code denn ich

oben gepostet habe.

C_REAL($1;$2)

C_REAL($ges)

C_INTEGER($3)

$CTOffscr:=CT New offscreen area

CT SET DOCUMENT SIZE ($CTOffscr;300;350)

$ges:=$1+$2

$laenge:=(150/$ges)*$1

$breite:=(150/$ges)*$2

$links:=(150-$laenge)/2

$oben:=(150-$breite)/2

ARRAY INTEGER(koord;8)

koord:=PROJ_AssistentWinkelVersch ($links;$oben;$links+$laenge;$oben;$links+$laenge;$oben+$breite;$links;$oben+$breite;$3)

ARRAY INTEGER(koordX;5)

ARRAY INTEGER(koordY;5)

For ($i;1;8)

koord{$i}:=koord{$i}+150

End for

koordX{1}:=koord{1}

koordX{2}:=koord{3}

koordX{3}:=koord{5}

koordX{4}:=koord{7}

koordY{1}:=koord{2}

koordY{2}:=koord{4}

koordY{3}:=koord{6}

koordY{4}:=koord{8}

koordX{5}:=koordX{1}

koordY{5}:=koordY{1}

$0:=CT Array to polygon ($CTOffscr;koordX;koordY)

$pict:=CT Area to picture ($CTOffscr;-2)

[Projekt];"ProjektAssistent"PictFormLage:=$pict

CT DELETE OFFSCREEN AREA ($CTOffscr)

Also danke, für die Antwort.

Also bei den Parametern:

AbmA=20

AbmB=10

Alpha=20 Grad

ergeben sich in folgenden Variablen die Werte:

links=25

oben=50

laenge=100

breite=50

koord{1}=-25

koord{2}=55

koord{3}=-57

koord{4}=87

koord{5}=-74

koord{6}=134

koord{7}=-42

koord{8}=102

Ich habe das mal mit Excel nachvollzogen, und komme auf diese Werte (gerundet):

6

56

100

90

83

137

-11

103

Das sieht immer noch wie ein Rechteck aus. Deine Y-Werte sind mehr oder weniger in Ordnung, aber deine X-Werte sind alle zu klein, eigenartigerweise paarweise um denselben Betrag.

Zeig doch bitte mal folgende Werte:

$alpha

Sin($alpha)

Cos($alpha)

$1*Cos($alpha)

$2*Sin($alpha)

So danke mal für die Antwort.

Also selbe Parameter wie vorher, folgende Werte:

alpha=0,3490658503988658956

Sin(alpha)=0,3420201433256687129

Cos(alpha=0,9396926207859

$1*Cos(alpha)=23,49231551964771114

$2*Sin(alpha)=17,10100716628343420

alpha=0,3490658503988658956

Sin(alpha)=0,3420201433256687129

Cos(alpha=0,9396926207859

$1*Cos(alpha)=23,49231551964771114

$2*Sin(alpha)=17,10100716628343420

Also sin(0,3490658503988658956) ist bei mir 0,006092310707817051148494877336295.

Cosinus bei ca. 0,99. :confused:

Wieso lässt du alpha nicht auf 20 (Grad)?

Naja, hab bei den Winkelfunktionen in 4th Dimension nachgeschaut, und angeblich benötigen diese Funktionen die Winkelangabe in Radiant und die Umrechnung dafür ist "Winkel*Degree". Sprich Degree ist eine Konstante.

Offenbar erwartet die Sinusfunktion, die du da benutzt, ihr Argument in Grad, nicht in Bogenmaß.

Ich hab die Unterscheidung schon immer gehasst, ja ok, jetzt passt das.:floet:

Sry, nicht in Radiant, sondern im Bogenmaß

So Leute, danke nochmal für alles. Es funktioniert jetzt.

Bin draufgekommen, dass bei der Fallunterscheidung alpha<0 oder >0 etwas nicht stimmte.

Danke für eure zahlreichen Antworten!!

Hier der richtige Code:

`$1...x1

`$2...y1

`$3...x2

`$4...y2

`$5...x3

`$6...y3

`$7...x4

`$8...y4

`$9...Winkelverschiebung um alpha(-180°-180°)

C_REAL($1;$2;$3;$4;$5;$6;$7;$8;$9)

C_REAL($x_1;$x_2;$x_3;$x_4;$y_1;$y_2;$y_3;$y_4)

C_REAL($alpha)

$alpha:=$9*Degree

If (($alpha=0) | ($9=180) | ($9=(-180)))

$x_1:=$1

$y_1:=$2

$x_2:=$3

$y_2:=$4

$x_3:=$5

$y_3:=$6

$x_4:=$7

$y_4:=$8

Else

If ($9<0)

$alpha:=$alpha*(-1)

$x_1:=($1*Cos($alpha))+($2*Sin($alpha))

$x_2:=($3*Cos($alpha))+($4*Sin($alpha))

$x_3:=($5*Cos($alpha))+($6*Sin($alpha))

$x_4:=($7*Cos($alpha))+($8*Sin($alpha))

$y_1:=(-$1*Sin($alpha))+($2*Cos($alpha))

$y_2:=(-$3*Sin($alpha))+($4*Cos($alpha))

$y_3:=(-$5*Sin($alpha))+($6*Cos($alpha))

$y_4:=(-$7*Sin($alpha))+($8*Cos($alpha))

Else

$x_1:=($1*Cos($alpha))+($2*Sin($alpha))

$x_2:=($3*Cos($alpha))+($4*Sin($alpha))

$x_3:=($5*Cos($alpha))+($6*Sin($alpha))

$x_4:=($7*Cos($alpha))+($8*Sin($alpha))

$y_1:=(-$1*Sin($alpha))+($2*Cos($alpha))

$y_2:=(-$3*Sin($alpha))+($4*Cos($alpha))

$y_3:=(-$5*Sin($alpha))+($6*Cos($alpha))

$y_4:=(-$7*Sin($alpha))+($8*Cos($alpha))

End if

End if

ARRAY INTEGER(koord;8)

koord{1}:=$x_1

koord{2}:=$y_1

koord{3}:=$x_2

koord{4}:=$y_2

koord{5}:=$x_3

koord{6}:=$y_3

koord{7}:=$x_4

koord{8}:=$y_4

$0:=koord

So Leute, danke nochmal für alles. Es funktioniert jetzt.

Bin draufgekommen, dass bei der Fallunterscheidung alpha<0 oder >0 etwas nicht stimmte.

:eek

Das Problem hat mit der Fallunterscheidung für das Vorzeichen nicht das Geringste zu tun. Die ist immer noch überflüssig und falsch.

Das Problem ist, dass die Programmiersprache, die du da benutzt, offenbar Punkt-vor-Strich nicht beherrscht. Die zusätzlichen Klammern in den Formeln sind es, die das Problem gelöst haben.

:upps

Ok, danke, ist auch möglich. Hatte das Problem nämlich auch schon öfters, dass eine Compilermeldung kam, wenn keine Klammern gesetzt wurden. Obwohl das in anderen Sprachen (Java, C++) ziemlich egal ist.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.