1
$\begingroup$

here is a figure (fig_1) illustrating a space-filling spiral curve constitutes a triangle.

enter image description here

i am trying to draw this mathematically.

with @David K's help, we got this figure (fig_2)

draw a space-filling curve

by using this formula

\begin{align} &(-r, r) \\ &(r,-r) \\ &(-r,-r) \\ &(-2r,2r) \\ &(2r,-2r) \\ &(-2r,-2r) \\ &(-3r,3r) \\ &(3r,-3r) \\ &(-3r,-3r) \\ &(-4r,4r) \\ &(4r,-4r) \\ &(-4r,-4r) \\ &\ldots \end{align}

here is a piece of python code to implement the formula

import numpy as np
x = np.array([])
y = np.array([])
for r in range(1,9):
    x = np.append(x, np.array([-r,r,-r]))
    y = np.append(y, np.array([r,-r,-r]))
plt.plot(x,y)

fig_2 is very close to fig_1 though, there seems to be a bug. how to improve this formula?

$\endgroup$
1
$\begingroup$

thanks to @David K

doubling all the positive coordinates might work better

import numpy as np
x = np.array([])
y = np.array([])
for r in range(9):
    x = np.append(x, np.array([-r,2*r,-r]))
    y = np.append(y, np.array([2*r,-r,-r]))
plt.plot(x,y)

outputs

enter image description here

$\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.