chiark / gitweb /
moebius: pass nt and it to MoebiusHalf, rather than just t
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Apr 2018 19:52:12 +0000 (20:52 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Apr 2018 19:52:12 +0000 (20:52 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
moebius.py

index 34111728052e03c6b6dbdcceaf4a88f03d7f0a60..58d79f63978cde303e5eb5bea293ad60ad1fd4bf 100644 (file)
@@ -69,7 +69,7 @@ class Twirler(ParametricCircle):
     return cos(zeta) * r + sin(zeta) * tw._axis
 
 class MoebiusHalf:
-  def __init__(m, nu):
+  def __init__(m, nu, nt):
     '''
      MoebiusHalf().edge is a Twirler for the edge,
       expecting theta = u * tau (see MoebiusHalf().point)
@@ -78,9 +78,11 @@ class MoebiusHalf:
     m.edge    = Twirler(origin,  unit_z, unit_x, -2, tau/2)
     m.midline = Twirler(-unit_z, unit_z, unit_y, -0.5, 0)
     m.nu      = nu
+    m.nt      = nt
     m._thetas = [ u * tau for u in np.linspace(0, 1, nu+1) ]
     m._cp2b = BezierSegment([ (c,) for c in [0.33,0.33, 1.50]])
     m._beziers = [ m._bezier(theta) for theta in m._thetas ]
+    m._t_vals = np.linspace(0, 1, m.nt+1)
   def _bezier(m, theta, constructor=DoubleCubicBezier):
     cp = [None] * 4
     cp[0] =               m.edge   .point(theta)
@@ -94,15 +96,16 @@ class MoebiusHalf:
     cp[1] = cp[0] + cp1scale * m.edge   .dirn (theta)
     cp[2] = cp[3] + cp2scale * m.midline.dirn (theta*2)
     return constructor(cp)
-  def point(m, iu, t):
+  def point(m, iu, it):
     '''
     0 <= iu <= nu     meaning 0 <= u <= 1
                       along the extent (well, along the edge)
                        0 and 1 are both the top half of the flat traverse
                        0.5        is the bottom half of the flat traverse
-    0 <=  t   <= 1    across the half-traverse
+    0 <= it <= nt     across the half-traverse
                        0 is the edge, 1 is the midline
     '''
+    t = m._t_vals[it]
     return np.array(m._beziers[iu].point_at_t(t))
 
   def details(m, iu, t):
@@ -144,8 +147,7 @@ class Moebius():
     m.nv = nv
     m.nw = nw
     m.nt = nw/2
-    m._t_vals = np.linspace(0, 1, m.nt+1)
-    m.h = MoebiusHalf(nu=nv*2)
+    m.h = MoebiusHalf(nu=nv*2, nt=m.nt)
 
   def _vw2tiu_kw(m, v, w):
     if w <= m.nt:
@@ -156,7 +158,7 @@ class Moebius():
       iu = m.nv + v
     #print('v,w=%d,%d => it,iu=%d,%d' % (v,w,it,iu),
     #      file=sys.stderr)
-    return { 't': m._t_vals[it], 'iu': iu }
+    return { 'it': it, 'iu': iu }
 
   def point(m, v, w):
     return m.h.point(**m._vw2tiu_kw(v,w))