chiark / gitweb /
introduce Moebius with less silly numbering
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Nov 2017 23:35:29 +0000 (23:35 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Nov 2017 23:35:29 +0000 (23:35 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
check.py
moebius.py

index 5994aafc728969e0e4cd8dc4384a2604592f3e9e..1f9875d35d8f6f2d36324eda4abfb86af2556dc3 100644 (file)
--- a/check.py
+++ b/check.py
@@ -8,20 +8,22 @@ import numpy as np
 
 from moebius import *
 
-nu = 40
+nv = 40
+nw = 40
 
-m = MoebiusHalf(nu)
+m = Moebius(nv, nw)
 
-ts = np.linspace(0, 1, 40)
+vs = range(0, nv+1)
+ws = range(0, nw+1)
 
-thetas = np.linspace(0, tau, 40)
+#ts = np.linspace(0, 1, 40)
 
-c0 = curve( color=color.red, pos = [ m.edge.point(th) for th in thetas ] )
-c1 = curve( color=color.blue, pos = [ m.midline.point(th) for th in thetas ] )
+#thetas = np.linspace(0, tau, 40)
+#c0 = curve( color=color.red, pos = [ m.edge.point(th) for th in thetas ] )
+#c1 = curve( color=color.blue, pos = [ m.midline.point(th) for th in thetas ] )
 
-for iu in range(0, nu):
-  c2 = curve( pos = [ m.point(iu, t) for t in ts ] )
+for v in vs:
+  c2 = curve( pos = [ m.point(v,w) for w in ws ] )
 
-for t in ts:
-  c3 = curve( color=color.yellow, pos = [ m.point(iu, t)
-                                          for iu in range(0, nu/2+1) ] )
+for w in ws:
+  c3 = curve( color=color.yellow, pos = [ m.point(v,w) for v in vs ] )
index 9dca951c19de604bbb59b8580ec9aa06d8d7c5a2..37b7676825d76b5830ad0147e123b37474d57493 100644 (file)
@@ -80,3 +80,31 @@ class MoebiusHalf:
                        0 is the edge, 1 is the midline
     '''
     return m._beziers[iu].point_at_t(t)
+
+class Moebius(MoebiusHalf):
+  def __init__(m, nv, nw):
+    '''
+      0 <= v <= nw    along the extent,    v=0 is the flat traverse
+      0 <= w <= nv    across the traverse  nw must be even
+      the top is both   v=0, w=0  v=nv, w=nw
+    '''
+    assert(nw % 1 == 0)
+    m.nv = nv
+    m.nw = nw
+    m.nt = nw/2
+    m._t_vals = np.linspace(0, 1, m.nt+1)
+    MoebiusHalf.__init__(m, nu=nv*2)
+
+  def _vw2tiu_kw(m, v, w):
+    if w <= m.nt:
+      it = w
+      iu = v
+    else:
+      it = m.nw - w
+      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 }
+
+  def point(m, v, w):
+    return MoebiusHalf.point(m, **m._vw2tiu_kw(v,w))