chiark / gitweb /
moebius before remove Twirler
[moebius3.git] / moebius.py
1
2 import numpy as np
3
4 tau = np.pi * 2
5
6 origin =  (0,0,0)
7 unit_x = (1,0,0)
8 unit_y = (0,1,0)
9 unit_z = (0,0,1)
10
11 def ParametricCircle:
12   def __init__(pc, c, r0, r1):
13     ''' circle centred on c
14         with theta=0 point at c+r0
15         and with theta=tau/4 point at c+r1 '''
16     pc._c  = c
17     pc._r0 = r0
18     pc._r1 = r1
19     pc._axis = np.cross(r0, r1)
20   def point(pc, theta):
21     return pc._c + pc._r0 * cos(theta) + pc._r1 * sin(theta)
22
23 def Twirler(ParametricCircle):
24   def __init__(tw, c, r0, r1, cycles, begin):
25     ''' circle centred on c, etc.
26         but with an orientation at each point, orthogonal to
27         the circle
28 '''
29     ParametricCircle.__init__(tw, c, r0, r1)
30     tw._cycles = cycles
31   def 
32
33 class Moebius:
34   def __init__(m, n_u):
35     m._edge = ParametricCircle(origin, unit_z, unit_x)
36     m._midline = ParametricCircle(-unit_z, unit_z, unit_y)
37     m._beziers = [ self._bezier(u) for u in np.linspace(0, 1, n_u) ]
38   def _bezier(u):
39     theta = u * tau
40     cp0 = m._edge.point(theta)
41     cp3 = m._midline.point(theta*2)
42