From: Ian Jackson Date: Sat, 4 Nov 2017 23:35:29 +0000 (+0000) Subject: introduce Moebius with less silly numbering X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=bf7c707674c89787597672d33aac096e13374209;p=moebius3.git introduce Moebius with less silly numbering Signed-off-by: Ian Jackson --- diff --git a/check.py b/check.py index 5994aaf..1f9875d 100644 --- 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 ] ) diff --git a/moebius.py b/moebius.py index 9dca951..37b7676 100644 --- a/moebius.py +++ b/moebius.py @@ -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))