# Circle Morphing into a triangle

**URL:** <https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478>\
**Category:** Staff Picks\
**Tags:** fun-and-play, geometry, graphics-and-visualization, interface-construction, staff-pick\
**Created:** [November 5, 2017, 6:29pm UTC](https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478 "2017-11-05T18:29:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fortsaint](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fortsaint/32/9427_2.png) [@fortsaint](https://community.wolfram.com/u/fortsaint)\
**Post date:** [November 5, 2017, 6:29pm UTC](https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478/1 "2017-11-05T18:29:01Z")

</div>

In this youtube video [Coding Challenge #81.1: Circle Morphing](https://www.youtube.com/watch?v=u2D4sxh3MTs&t=365s) there is this guy solving a Javascript code challenge about morphing an equilateral triangle into a circle. Here is a one-line Wolfram expression written in a pure functional style that returns the solution using only built-in function.

```
{Interpolation[#2, InterpolationOrder -> 1], Most@Array[# &, 50, {#1, #2}] & @@ #1} &~MapThread~(
Partition[#, 2, 1] & /@ {First@Transpose@#, #} &@Table[{Cos@x, Sin@x}, {x, -Pi/6, 2 Pi - Pi/6, 2 Pi/3}]) // 
       Join @@ MapThread[Transpose@{#2, #1@#2} &, Transpose@#] & // 
      Transpose@{#, Most@N@Table[{Cos@x, Sin@x}, {x, -Pi/6, 2 Pi - Pi/6, 2 Pi/(Length@#)}]} & // 
     Animate[.5 (Sin@k First@# + (1 - Sin@k) Last@#) & /@ Append[#, First@#] // Graphics[{Thickness@.01, Line@#},
     PlotRange -> {{-.5, .5}, {-.6, .6}}] &, {k, 0, Pi/2}, AnimationDirection -> ForwardBackward, AnimationRate -> .5] &

```

---

<div class="post-metadata">

**Author:** ![sghuisman](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sghuisman/32/27850_2.png) [@sghuisman](https://community.wolfram.com/u/sghuisman)\
**Post date:** [November 5, 2017, 8:23pm UTC](https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478/2 "2017-11-05T20:23:34Z")

</div>

“one-line”

nicely done!

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [November 5, 2017, 11:13pm UTC](https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478/3 "2017-11-05T23:13:35Z")

</div>

tri[n\_] =  
Sum[RealAbs[x Cos[(2 [Pi] i)/3] + y Sin[(2 [Pi] i)/3] - 1/3]^  
n, {i, 3}] - 1;

```
ContourPlot[
 Evaluate[Table[tri[n] == 0, {n, 2, 10}]], {x, -1.5, 1.5}, {y, -1.5, 
  1.5}]

```

 ![tri.jpg](https://global.discourse-cdn.com/wolfram/original/2X/c/cefecf0d308591a8ed9cbbd5d5e361840a3846a6.jpeg)

---

<div class="post-metadata">

**Author:** ![fortsaint](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fortsaint/32/9427_2.png) [@fortsaint](https://community.wolfram.com/u/fortsaint)\
**Post date:** [November 6, 2017, 12:32am UTC](https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478/4 "2017-11-06T00:32:44Z")

</div>

Interesting! But it seems that your code simply plots different polynomial functions. I would not call this a proper morphing.  
In my example, we start with some points forming a tringle and some points forming the circle. Then, all the intermediate lists of points are generated by averaging the corresponding points with a shifting weight. As a matter of fact, if you replace the first table (which defines the three triangle vertexes)

```
Table[{Cos@x, Sin@x}, {x, -Pi/6, 2 Pi - Pi/6, 2 Pi/3}]

```

with some random points like

```
RandomReal[{},{8,2}]

```

the code generates a morphing from those random points to the circle.  
In general you can even get rid of the circle and start with two lists of points having the same lenght; my code will morph one into the other.

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [November 6, 2017, 3:54am UTC](https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478/5 "2017-11-06T03:54:58Z")

</div>

Here’s a similar idea, with different coding, and a dynamic clock to animate the morphing:

```
CirclePoints[{1., Pi/2}, 3*25] //
  {Join @@ MapThread[Most@*Subdivide, {#, RotateLeft@#, #2 {1, 1, 1}}] &[CirclePoints[{1., Pi/2}, 3], Length@#/3], #} & //
 Graphics[
   GraphicsComplex[
    {Cos[Clock[Infinity]], Sin[Clock[Infinity]]}^2 .# // Dynamic,
    {EdgeForm[Thick], White, Polygon@Range@Length@First@#}
    ],
   PlotRange -> 1.02] &

```

---

<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:** [November 10, 2017, 1:37pm UTC](https://community.wolfram.com/t/circle-morphing-into-a-triangle/11478/6 "2017-11-10T13:37:26Z")

</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/fortsaint)! Thank you, keep it coming!
