2
$\begingroup$

I have a Voronoi mesh, given by

L1 = 5; L2 = 5; ar = Automatic;
pts = Flatten[Table[{3/2 i, Sqrt[3] j + Mod[i, 2] Sqrt[3]/2}, {i, L2}, {j, L1}],1] // N;
mesh = VoronoiMesh[pts, AspectRatio -> ar]

enter image description here

If instead we set the aspect ratio ar = 1, we get

enter image description here

which is slightly different. This makes sense since AspectRatio is with respect to the image box size.

My goal is to scale this first image in the horizontal (or vertical) direction by a factor scale. At first I thought about using something like AspectRatio -> scale, but it doesn't work because of the Automatic inconsistency. Any ideas around this? Ideally I would like scale = 1 to correspond to the first image, and then stretch the image from here.

I know about Scale and Scaled for a Graphics object, so maybe I could convert the mesh to a Graphics object? Any ideas?

This is a sketch of what I want

enter image description here

$\endgroup$
2
$\begingroup$

You can use the special form ImageSize -> 1 -> {a,b} for setting image size:

Row[Table[Labeled[
  VoronoiMesh[pts, PlotRangePadding -> 0, Frame -> True, ImageSize -> 1 -> 20 {s, 1}],
  "s = " <> ToString[s], Top], {s, { .8, 1, 1.3, 2}}], Spacer[5]]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ So as far as I understood, a and b work as scaling factors in the x and y directions? $\endgroup$ – sam wolfe Feb 19 at 13:02
  • $\begingroup$ @samwolfe, that's right. $\endgroup$ – kglr Feb 19 at 13:16
  • $\begingroup$ Just getting one annoying thing: whenever I evaluate the cell, select one of the output images and zoom in or out with the corner and side interactive widgets, the image gets automatically descaled, and I can't get it back to normal. Any way around this? $\endgroup$ – sam wolfe Feb 19 at 15:48
  • $\begingroup$ @sam, It may be a version/os-related issue. Interactive re-sizing works as expected in version 11.3 (windows 10 -64 bit) $\endgroup$ – kglr Feb 19 at 18:13
  • 1
    $\begingroup$ @sam, sorry spoke too soon. I had tried the panel with s=1. In other panels I have the same issue. To fix the issue add the option AspectRatio -> Full. $\endgroup$ – kglr Feb 19 at 19:29
4
$\begingroup$

What if you scale underlying points of MeshRegion? That way you have complete control and you can use geometric transformation functions like ScalingTransform, RotationTransform, etc.

(* mesh comes form OP's code *)
newCrds = ScalingTransform[{2, 1}] /@ MeshCoordinates[mesh]
MeshRegion[newCrds, MeshCells[mesh, 2], Frame -> True]

scaled_mesh

| improve this answer | |
$\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.