2
$\begingroup$

I have the following,

Flatten[MapAt[Reverse, 2]@
Table[{i, j}, {i, 0, 10, 10}, {j, 0, 90, 90}], 1]

that gives,

{{0, 0}, {0, 90}, {10, 90}, {10, 0}}

which are basically a rectangle coordinates, and shape will be

enter image description here

is there anyway I can rotate the coordinates by 45 degree, so the shape will look like the following,

enter image description here

$\endgroup$
0

1 Answer 1

3
$\begingroup$

You can achieve a rotation by using "GeometricTransformation" together with "RotationTransfrom". For your example we draw a line with the given coordinates:

dat = Flatten[
   MapAt[Reverse, 2]@Table[{i, j}, {i, 0, 10, 10}, {j, 0, 90, 90}], 1];
dat = Append[dat, dat[[1]]];
Graphics[{Line[dat]}]

enter image description here

Now we rotate the shape:

rot = RotationTransform[-Pi/4];
Graphics[GeometricTransformation[Line[dat], rot]]

enter image description here

To get the rotated coordinates, write:

rot[dat]

{{0, 0}, {45 Sqrt[2], 45 Sqrt[2]}, {50 Sqrt[2], 
  40 Sqrt[2]}, {5 Sqrt[2], -5 Sqrt[2]}, {0, 0}}
$\endgroup$
2
  • $\begingroup$ Thanks! I need to rotate the co-ordinates rather than the shape (GeometricTransformation). $\endgroup$
    – a019
    May 25 at 12:07
  • 1
    $\begingroup$ I added this part. $\endgroup$ May 25 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.