from numpy import cos, sin
from bezier import BezierSegment
-from helixish import HelixishCurve
from moenp import *
+from moebez import *
+from curveopt import *
import sys
-class DoubleCubicBezier():
- def __init__(db, cp):
- single = BezierSegment(cp)
- midpoint = np.array(single.point_at_t(0.5))
- mid_dirn = single.point_at_t(0.5 + 0.001) - midpoint
- mid_dirn /= np.linalg.norm(mid_dirn)
- ocp_factor = 0.5
- mid_scale = ocp_factor * 0.5 * (np.linalg.norm(cp[1] - cp[0]) +
- np.linalg.norm(cp[3] - cp[2]))
- db.b0 = BezierSegment([ cp[0],
- cp[1] * ocp_factor + cp[0] * (1-ocp_factor),
- midpoint - mid_dirn * mid_scale,
- midpoint ])
- db.b1 = BezierSegment([ midpoint,
- midpoint + mid_dirn * mid_scale,
- cp[2] * ocp_factor + cp[3] * (1-ocp_factor),
- cp[3] ])
- def point_at_t(db, t):
- if t < 0.5:
- return db.b0.point_at_t(t*2)
- else:
- return db.b1.point_at_t(t*2 - 1)
-
class ParametricCircle:
def __init__(pc, c, r0, r1):
''' circle centred on c
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)
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 ]
- def _bezier(m, theta):
+ m._dbeziers = [ m._dbezier(theta) for theta in m._thetas ]
+ #check = int(nu/3)-1
+ #checks = (
+ # m._dbezier(m._thetas[check], OptimisedCurve),
+ # m._dbezier(m._thetas[check+1], OptimisedCurve),
+ # m._dbezier(m._thetas[check+2], OptimisedCurve),
+ #)
+ #for c in checks: c.point_at_it(0)
+ def _dbezier(m, theta, dconstructor=OptimisedCurve):
cp = [None] * 4
cp[0] = m.edge .point(theta)
cp[3] = m.midline.point(theta*2)
# file=sys.stderr)
cp[1] = cp[0] + cp1scale * m.edge .dirn (theta)
cp[2] = cp[3] + cp2scale * m.midline.dirn (theta*2)
- return HelixishCurve(cp)
- def point(m, iu, t):
+ return dconstructor(cp, m.nt)
+ 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
'''
- return np.array(m._beziers[iu].point_at_t(t))
+ return np.array(m._dbeziers[iu].point_at_it(it))
def details(m, iu, t):
'''
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:
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))