In QGIS I have a point feature with "Rotation" field. Using the geometry builder I am trying to build square geometries based on the XY as centre and rotated based on the "Rotation" field using the expression below.
geom_from_wkt(
'POLYGON(('||
(((x( centroid( $geometry) ) + 0.5)*(cos(radians("Rotation"))))-((y( centroid( $geometry) ) + 0.5)*(sin(radians("Rotation")))))||' '||(((x( centroid( $geometry) ) + 0.5)*(sin(radians("Rotation"))))+((y( centroid( $geometry) ) + 0.5)*(cos(radians("Rotation")))))||','||
(((x( centroid( $geometry) ) + 0.5)*(cos(radians("Rotation"))))-((y( centroid( $geometry) ) - 0.5)*(sin(radians("Rotation")))))||' '||(((x( centroid( $geometry) ) + 0.5)*(sin(radians("Rotation"))))+((y( centroid( $geometry) ) - 0.5)*(cos(radians("Rotation")))))||','||
(((x( centroid( $geometry) ) - 0.5)*(cos(radians("Rotation"))))-((y( centroid( $geometry) ) - 0.5)*(sin(radians("Rotation")))))||' '||(((x( centroid( $geometry) ) - 0.5)*(sin(radians("Rotation"))))+((y( centroid( $geometry) ) - 0.5)*(cos(radians("Rotation")))))||','||
(((x( centroid( $geometry) ) - 0.5)*(cos(radians("Rotation"))))-((y( centroid( $geometry) ) + 0.5)*(sin(radians("Rotation")))))||' '||(((x( centroid( $geometry) ) - 0.5)*(sin(radians("Rotation"))))+((y( centroid( $geometry) ) + 0.5)*(cos(radians("Rotation")))))||','||
(((x( centroid( $geometry) ) + 0.5)*(cos(radians("Rotation"))))-((y( centroid( $geometry) ) + 0.5)*(sin(radians("Rotation")))))||' '||(((x( centroid( $geometry) ) + 0.5)*(sin(radians("Rotation"))))+((y( centroid( $geometry) ) + 0.5)*(cos(radians("Rotation")))))||','||
'))')
My rotation values are in degrees hence the conversion to radians but any feature with a rotation does not show up at all, features with no rotation value set show up as squares aligned North to South. Can someone tell me where I went wrong?