7
$\begingroup$

I noticed DiscretizeGraphics does not work correctly with transformed Graphics such as

Graphics[Rotate[Rectangle[], 30°]]

graphics1

Both using Rotate and GeometricTransformation together with RotationTransform yield EmptyRegion[2] when DiscretizeGraphics is used.

Graphics[Rotate[Rectangle[], 30°]] // DiscretizeGraphics   
(* EmptyRegion[2] *)

GeometricTransformation[Rectangle[], 
RotationTransform[30°]]] // Graphics // DiscretizeGraphics
(* EmptyRegion[2] *)

Is this a bug? Is there a workaround?

$\endgroup$
6
$\begingroup$

Here are a four possibilities. Two of them are due to @JM's comments. (Thanks!) All of them are based on the fact that Rectangle[] can be used as a geometric region as well as a graphics primitive, and they all use TransformedRegion to get the rotation rather than GeometricTransformation, RotationTransform or Rotate.

Define the rotated rectangle as a region:

reg = TransformedRegion[Rectangle[], RotationTransform[π/6]]

(* Parallelogram[{0, 0}, {{-(1/2), Sqrt[3]/2}, {Sqrt[3]/2, 1/2}}] *)

Then we can do

GraphicsRow[
 Through[{DiscretizeRegion, DiscretizeGraphics, 
          BoundaryDiscretizeRegion, BoundaryDiscretizeGraphics}@reg]
 ]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ BoundaryDiscretizeRegion[] and BoundaryDiscretizeGraphics[] can be used here too, of course. $\endgroup$ – J. M. is away Nov 1 '17 at 14:52
  • $\begingroup$ @J.M. Thanks for that. I've updated the answer. $\endgroup$ – aardvark2012 Nov 1 '17 at 23:31
2
$\begingroup$

For the time being a workaround is using first DiscretizeGraphics and then transforming the region e.g.

Rectangle[] // DiscretizeGraphics //TransformedRegion[#, RotationTransform[30°]]& 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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