Rechteck drehen

Status
Nicht offen für weitere Antworten.

Paladin

Bekanntes Mitglied
Hi,

ich will ein Rechteck(2D) in einem bestimmten Winkel drehen und dann anzeigen.

Bei einem Winkel von 0 wird das Rechteck noch korrekt angezeigt aber sobald
der Winkel verändert wird stimmt die Berechnung nicht mehr.

Was ist an der Formel falsch?

Code:
    int polydata[] = new int[];
    polydata[0] = (int)((xPos*Math.cos(rotation))+(yPos*Math.sin(rotation)));
    polydata[1] = (int)((xPos*Math.sin(rotation))+(yPos*Math.cos(rotation)));
    polydata[2] = (int)(((xPos+objWidth)*Math.cos(rotation))+(yPos*Math.sin(rotation)));
    polydata[3] = (int)(((xPos+objWidth)*Math.sin(rotation))+(yPos*Math.cos(rotation)));
    polydata[4] = (int)(((xPos+objWidth)*Math.cos(rotation))+(yPos+objHeight)*Math.sin(rotation));
    polydata[5] = (int)(((xPos+objWidth)*Math.sin(rotation))+(yPos+objHeight)*Math.cos(rotation));
    polydata[6] = (int)(((xPos*Math.cos(rotation)))+(yPos+objHeight)*Math.sin(rotation));
    polydata[7] = (int)(((xPos*Math.sin(rotation)))+(yPos+objHeight)*Math.cos(rotation));
    polydata[8] = polydata[0];
    polydata[9] = polydata[1];

Vielen Dank im voraus.

Gruß

Paladin
 
Ja.
Ich benutze auch das SWT und ich glaube da gibts Affine Transform gar nicht.
Sicherlich könnte ich das Koordinatensystem drehen und dann das Rechteck zeichnen aber
ich wills erstmal so versuchen.
 
die Drehmatrix scheint falsch zu sein.
xneu = x*cos(Phi) + y*sin(Phi)
yneu = -x*sin(Phi) + y*cos(Phi)

und außerdem wären Double-Werte empfehlenswert
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben