<p>This isn't really a direct answer to this question (that already has an answer anyway), but might interest people who want to implement this algorithm in 3D.</p>

<p>I had to try implementing this algorithm to generate 3D spirals in blender using Python (could easily be converted to drawing with PIL or Matplotlib in 2D). So here's the algorithm and result:</p>

<p><a href="https://i.sstatic.net/dcoM7.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dcoM7.jpg" alt="enter image description here"></a></p>

<pre><code>import bpy
from math import cos, sin
S = bpy.context.scene

def add_archimedian_spiral( size = 0.1, length = 500, height = 1, name = 'archispiral' ):
    mesh = bpy.data.meshes.new( name = name )

    o = bpy.data.objects.new(name, mesh)
    o.location = (0,0,0) # place at object origin
    S.objects.link( o )

    z     = 0
    verts = []  
    for i in range( length ):
        angle = 0.1 * i
        x     = ( 2 * size * angle ) * cos( angle )
        y     = ( 2 * size * angle ) * sin( angle )
        z    += i / 10000 * height
        verts.append((x,y,z))

    edges = []
    for i in range( len( verts ) ):
        if i == len( verts ) - 1: break
        edges.append((i, i+1))

    mesh.from_pydata( verts, edges, [] )

add_archimedian_spiral( size = 0.2, length = 500, height = 6 )
</code></pre>

CC BY-SA 3.0
2015-12-24T09:37:43.297Z
Does this do the same thing except with an increase on the Z height on each iteration of the for loop?
David
CC BY-SA 3.0
2015-12-24T09:54:29.600Z
Pretty much, except its always symmetrical (istead of the original a and b, I used a uniform `size` param).
TLousky
CC BY-SA 3.0
2015-12-23T13:22:21.527Z
2015-12-26T15:50:42.340Z
2015-12-26T15:50:42.340Z
TLousky
<p>Figured it out :) The dominos are now being placed along the X and Y coordinates generated by the function. </p>

<p>The original code in the question was plotting a wave of points outwards from the centre position or origin and was not what I wanted. What I needed was for each point to follow the <code>Archimedean spiral</code> with a certain space between the spirals. </p>

<p>Initially I used <code>integer</code> values to store the <code>x</code> and <code>y</code> coordinates but this was causing a precision error by truncating the <code>floating point</code> value in order to store it in the <code>integer</code> data type.</p>

<p>The below example generates points along the spiral continuously, relative to the <code>maxPoints</code> value. </p>

<pre><code>float x = 0;
float y = 0;
float angle = 0.0f;

// Space between the spirals
int a = 2, b = 2;

for (int i = 0; i &lt; maxPoints; i++)
{
    angle = 0.1 * i;
    x = (a + b * angle) * cos(angle);
    y = (a + b * angle) * sin(angle);

    plot(x, y);
}
</code></pre>

<p>Code for the project is on <a href="https://github.com/damorton/bullet-dominos/blob/master/CAPhysics/Chapter4.2/BasicDemo.cpp" rel="nofollow">GitHub</a>, you will need <a href="http://bulletphysics.org/wordpress/" rel="nofollow">Bullet</a> and <a href="http://freeglut.sourceforge.net/" rel="nofollow">freeglut</a></p>

CC BY-SA 3.0
2015-12-21T20:25:45.710Z
This answer would be even better if you explained what the problem turned out to be and what you changed to fix it...
trichoplax is on Codidact now
CC BY-SA 3.0
2015-12-22T21:22:27.333Z
Ill update the question and answer now with more info.
David
CC BY-SA 3.0
2015-12-21T12:24:56.043Z
2015-12-22T21:48:24.973Z
2015-12-22T21:48:24.973Z
David
<p>Im trying to plot the x and y positions of an <a href="https://en.wikipedia.org/wiki/Archimedean_spiral" rel="noreferrer">Archimedean spiral</a> in C++.</p>

<p><a href="https://i.sstatic.net/wSmFI.png" rel="noreferrer"><img src="https://i.sstatic.net/wSmFI.png" alt="Archimedean spiral"></a></p>

<p>So far I've been trying something like this, but no luck:</p>

<pre class="lang-cpp prettyprint-override"><code>int dx = 0;
int dy = 0;
int x = 0;
int y = 0;

for (int i = 0; i &lt; maxPoints; i++)
{
    dx = sin(i * PI / 2);
    dy = cos(-i * PI / 2);
    x += dx;
    y += dy;

    plot(x, y);    
}
</code></pre>

<p>EDIT: More info</p>

<p>I'm developing a 3D game application that demonstrates the use of the <a href="http://bulletphysics.org/wordpress/" rel="noreferrer">Bullet</a> physics engine by simulating dominos. Instead of placing the dominos in the scene manually I want to use some math to do it for me :)</p>

<p>For anyone who is interested here it is on <a href="https://github.com/damorton/bullet-dominos" rel="noreferrer">GitHub</a>.</p>

CC BY-SA 3.0
2015-12-22T01:50:08.923Z
The problem seems to be that all variables are `int`. In particular, `dx` and `dy` will probably get 0.
lhf
<c++><geometry>
Archimedean spiral in C++
David
# Archimedean spiral in C++

(Asked by: username_0 on 2015-12-21)

Im trying to plot the x and y positions of an [Archimedean spiral](https://en.wikipedia.org/wiki/Archimedean_spiral) in C++.

[![Archimedean spiral](https://i.sstatic.net/wSmFI.png)](https://i.sstatic.net/wSmFI.png)

So far I've been trying something like this, but no luck:

```cpp
int dx = 0;
int dy = 0;
int x = 0;
int y = 0;

for (int i = 0; i < maxPoints; i++)
{
    dx = sin(i * PI / 2);
    dy = cos(-i * PI / 2);
    x += dx;
    y += dy;

    plot(x, y);    
}

```

EDIT: More info

I'm developing a 3D game application that demonstrates the use of the [Bullet](http://bulletphysics.org/wordpress/) physics engine by simulating dominos. Instead of placing the dominos in the scene manually I want to use some math to do it for me :)

For anyone who is interested here it is on [GitHub](https://github.com/damorton/bullet-dominos).

**Tags:** c++, geometry

> **Comments:**
> **username_1**: The problem seems to be that all variables are `int`. In particular, `dx` and `dy` will probably get 0.  

---

## 2 answers

### Answer by username_0 on 2015-12-21. Score: 7 | Accepted answer

Figured it out :) The dominos are now being placed along the X and Y coordinates generated by the function.

The original code in the question was plotting a wave of points outwards from the centre position or origin and was not what I wanted. What I needed was for each point to follow the `Archimedean spiral` with a certain space between the spirals.

Initially I used `integer` values to store the `x` and `y` coordinates but this was causing a precision error by truncating the `floating point` value in order to store it in the `integer` data type.

The below example generates points along the spiral continuously, relative to the `maxPoints` value.

```
float x = 0;
float y = 0;
float angle = 0.0f;

// Space between the spirals
int a = 2, b = 2;

for (int i = 0; i < maxPoints; i++)
{
    angle = 0.1 * i;
    x = (a + b * angle) * cos(angle);
    y = (a + b * angle) * sin(angle);

    plot(x, y);
}

```

Code for the project is on [GitHub](https://github.com/damorton/bullet-dominos/blob/master/CAPhysics/Chapter4.2/BasicDemo.cpp), you will need [Bullet](http://bulletphysics.org/wordpress/) and [freeglut](http://freeglut.sourceforge.net/)

> **Comments:**
> **username_3**: This answer would be even better if you explained what the problem turned out to be and what you changed to fix it...  
> **username_0**: Ill update the question and answer now with more info.  

---

### Answer by username_2 on 2015-12-23. Score: 4

This isn't really a direct answer to this question (that already has an answer anyway), but might interest people who want to implement this algorithm in 3D.

I had to try implementing this algorithm to generate 3D spirals in blender using Python (could easily be converted to drawing with PIL or Matplotlib in 2D). So here's the algorithm and result:

[![enter image description here](https://i.sstatic.net/dcoM7.jpg)](https://i.sstatic.net/dcoM7.jpg)

```
import bpy
from math import cos, sin
S = bpy.context.scene

def add_archimedian_spiral( size = 0.1, length = 500, height = 1, name = 'archispiral' ):
    mesh = bpy.data.meshes.new( name = name )

    o = bpy.data.objects.new(name, mesh)
    o.location = (0,0,0) # place at object origin
    S.objects.link( o )

    z     = 0
    verts = []  
    for i in range( length ):
        angle = 0.1 * i
        x     = ( 2 * size * angle ) * cos( angle )
        y     = ( 2 * size * angle ) * sin( angle )
        z    += i / 10000 * height
        verts.append((x,y,z))

    edges = []
    for i in range( len( verts ) ):
        if i == len( verts ) - 1: break
        edges.append((i, i+1))

    mesh.from_pydata( verts, edges, [] )

add_archimedian_spiral( size = 0.2, length = 500, height = 6 )

```

> **Comments:**
> **username_0**: Does this do the same thing except with an increase on the Z height on each iteration of the for loop?  
> **username_2**: Pretty much, except its always symmetrical (istead of the original a and b, I used a uniform `size` param).  

---

