# \[GIF\] Caught (Voronoi cells of stereographically projected pattern)

**URL:** <https://community.wolfram.com/t/gif-caught-voronoi-cells-of-stereographically-projected-pattern/11975>\
**Category:** Staff Picks\
**Tags:** computational-arts, geometry, graphics-and-visualization, interface-construction, staff-pick\
**Created:** [February 16, 2018, 9:10pm UTC](https://community.wolfram.com/t/gif-caught-voronoi-cells-of-stereographically-projected-pattern/11975 "2018-02-16T21:10:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![claytonshonkwiler](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/claytonshonkwiler/32/24940_2.png) [@claytonshonkwiler](https://community.wolfram.com/u/claytonshonkwiler)\
**Post date:** [February 16, 2018, 9:10pm UTC](https://community.wolfram.com/t/gif-caught-voronoi-cells-of-stereographically-projected-pattern/11975/1 "2018-02-16T21:10:29Z")

</div>

![r11Lqrc.gif](https://global.discourse-cdn.com/wolfram/original/2X/2/2ecb482b775298cce036c42bdf137564eff2a874.gif)

**Caught**

Continuing with the stereographic projection theme. This time, I generated a bunch of points arranged in spirals on the sphere, like so:

 ![5946Untitled-13.png](https://global.discourse-cdn.com/wolfram/original/3X/3/4/34f2d327129eba3d25d3cfac6ed23dc741a11817.png)

Then I stereographically project the points to the plane and compute the Voronoi diagram of the resulting points. Throw in a rotation of the sphere and you get the above animation.

As for the code, first of all we need the stereographic projection map:

```
Stereo[p_] := p[[;; -2]]/(1 - p[[-1]])

```

Next, we need to define the points. It turned out that without throwing in some noise in the definition of the points, `VoronoiMesh[]` would occasionally fail, which is why I put in the `RandomVariate[]` business in both cylindrical coordinates:

```
pts = With[{n = 20},
   Table[
    CoordinateTransformData["Cylindrical" -> "Cartesian", "Mapping"]
     [{Sqrt[1 - (z + #)^2], ? + RandomVariate[UniformDistribution[{-.00001, .00001}]] 
         + (z + # + 2)/2 * ?/2, z + #}
       &[RandomVariate[UniformDistribution[{-.00001, .00001}]]]
     ],
    {z, -.9, .9, 2/n}, {?, 0, 2 ? - 2 ?/n, 2 ?/n}]
   ];

```

Finally, then, here’s the animation:

```
With[{cols = RGBColor /@ {"#F5841A", "#03002C"}},
 Manipulate[
  VoronoiMesh[
   Stereo[RotationMatrix[?, {1., 0, 0}].#] & /@ Flatten[pts, 1],
   {{-4.1, 4.1}, {-4.1, 4.1}}, PlotTheme -> "Lines", PlotRange -> 4, 
   MeshCellStyle -> {{1, All} -> Directive[Thickness[.005], cols[[1]]]},
   ImageSize -> 540, Background -> cols[[-1]]],
  {?, 0, ?}
  ]
 ]

```

---

<div class="post-metadata">

**Author:** ![wolframcommunity](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/wolframcommunity/32/8335_2.png) [@wolframcommunity](https://community.wolfram.com/u/wolframcommunity)\
**Post date:** [February 18, 2018, 4:58pm UTC](https://community.wolfram.com/t/gif-caught-voronoi-cells-of-stereographically-projected-pattern/11975/2 "2018-02-18T16:58:56Z")

</div>

![2015-11-02_10-07-11.png](https://global.discourse-cdn.com/wolfram/original/3X/5/0/50e59c9ead62f729e7130d3ea1482555a75602b6.png)

- Congratulations! This post is now a [Staff Pick](http://community.wolfram.com/content?curTag=staff+picks) as distinguished by a badge on [your profile](http://community.wolfram.com/web/claytonshonkwiler)! Thank you, keep it coming!

---

<div class="post-metadata">

**Author:** ![pleasureoffiguring](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/pleasureoffiguring/32/18977_2.png) [@pleasureoffiguring](https://community.wolfram.com/u/pleasureoffiguring)\
**Post date:** [March 14, 2018, 3:12pm UTC](https://community.wolfram.com/t/gif-caught-voronoi-cells-of-stereographically-projected-pattern/11975/3 "2018-03-14T15:12:04Z")

</div>

Here are some quick tips for your future artwork:

1. The operation `RotationMatrix[?, {1, 0, 0}].# & /@ pts` can be recast into a more efficient form with a little linear algebra. Briefly, if you are mapping a premultiplication by a matrix over a list of points, this is equivalent to postmultiplying the list of points by the transpose of the matrix. That is, `A.# & /@ list` is just the same as `list.Transpose[A]`.

In this case, it is very fortuitous that the transpose of `RotationMatrix[]` takes on a very convenient form. To sum up, the compact version of this operation is `pts.RotationMatrix[-?, {1, 0, 0}]`.

1. You can redefine your function `Stereo[]` so that it acts on a list of points _en masse_, instead of you having to map it over each point:

* * *

With these considerations, we can redo the heart of your code as

```
Stereo[Flatten[pts, 1].RotationMatrix[-?, {1, 0, 0}]]

```

with `Stereo[]` defined for a list of points.

Anyway, nice artwork, as always! 🙂

---

<div class="post-metadata">

**Author:** ![claytonshonkwiler](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/claytonshonkwiler/32/24940_2.png) [@claytonshonkwiler](https://community.wolfram.com/u/claytonshonkwiler)\
**Post date:** [March 15, 2018, 5:01pm UTC](https://community.wolfram.com/t/gif-caught-voronoi-cells-of-stereographically-projected-pattern/11975/4 "2018-03-15T17:01:57Z")

</div>

Ah, that’s a good point! Even after all these years, I think I still have a bit of a mental block about representations of vectors in Mathematica, but of course you’re quite right that a list of vectors can be interpreted as a matrix whose rows are the given vectors.

I don’t like your redefinition of `Stereo[]` as much: with your definition I can’t apply it to a single point, only to a list of points. Of course, in this particular example I am applying to to a list of points, but this is a function that I reuse constantly, including in circumstances when I want to apply it to single points.

---

<div class="post-metadata">

**Author:** ![pleasureoffiguring](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/pleasureoffiguring/32/18977_2.png) [@pleasureoffiguring](https://community.wolfram.com/u/pleasureoffiguring)\
**Post date:** [March 16, 2018, 1:38pm UTC](https://community.wolfram.com/t/gif-caught-voronoi-cells-of-stereographically-projected-pattern/11975/5 "2018-03-16T13:38:28Z")

</div>

Yes, the implementation in my reply is intended for _en masse_ application of the stereographic transformation. If I were implementing `Stereo[]`, I would maintain both implementations, and use an argument check so that the applicable method is used.

That is: `Stereo[pt_?VectorQ] := (* stuff *)` would be the one-point case, corresponding to your implementation, and `Stereo[pt_?MatrixQ] := (* stuff *)` would be the many-point case, corresponding to my implementation.
