X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=moebius.py;h=e5a81acad9d0d458bbc823769b5cea55176e0801;hb=906edec3ef60cf3e0567c713b2a68688edb634d4;hp=4b8d640c5240f8b04a3ecf460d4238239f925b37;hpb=66469d04776a306afb8ec217c9be5a72bb1bb807;p=moebius3.git diff --git a/moebius.py b/moebius.py index 4b8d640..e5a81ac 100644 --- a/moebius.py +++ b/moebius.py @@ -5,19 +5,11 @@ import numpy as np from numpy import cos, sin from bezier import BezierSegment +from helixish import HelixishCurve +from moenp import * import sys -tau = np.pi * 2 - -origin = np.array((0,0,0)) -unit_x = np.array((1,0,0)) -unit_y = np.array((0,1,0)) -unit_z = np.array((0,0,1)) - -def unit_v(v): - return v / np.linalg.norm(v) - class DoubleCubicBezier(): def __init__(db, cp): single = BezierSegment(cp) @@ -89,8 +81,10 @@ class MoebiusHalf: m.nu = nu 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._beziers = [ m._bezier(theta, HelixishCurve) for theta in m._thetas ] + #check = int(nu/3) + #m._beziers[check] = m._bezier(m._thetas[check], HelixishCurve) + def _bezier(m, theta, constructor=DoubleCubicBezier): cp = [None] * 4 cp[0] = m.edge .point(theta) cp[3] = m.midline.point(theta*2) @@ -102,7 +96,7 @@ class MoebiusHalf: # file=sys.stderr) cp[1] = cp[0] + cp1scale * m.edge .dirn (theta) cp[2] = cp[3] + cp2scale * m.midline.dirn (theta*2) - return DoubleCubicBezier(cp) + return constructor(cp) def point(m, iu, t): ''' 0 <= iu <= nu meaning 0 <= u <= 1 @@ -119,7 +113,7 @@ class MoebiusHalf: returns tuple of 4 vectors: - point location - normal (+ve is in the +ve y direction at iu=t=0) unit vector - - along extend (towrds +ve iu) unit vector + - along extent (towrds +ve iu) unit vector - along traverse (towards +ve t) unit vector ''' if iu == m.nu: @@ -132,7 +126,7 @@ class MoebiusHalf: else: vec_u = unit_v( m.point(iu+1, t) - p ) normal = np.cross(vec_u, vec_t) - return (p, normal, vec_u, vec_t) + return p, normal, vec_u, vec_t def point_offset(m, iu, t, offset): ''' @@ -174,3 +168,17 @@ class Moebius(): return m.h.point_offset(offset= offset if w <= m.nt else -offset, **m._vw2tiu_kw(v,w)) + + def details(m, v, w): + ''' + returns tuple of 4 vectors: + - point location + - normal (+ve is in the +ve y direction at iu=t=0) unit vector + - along extent (towrds +ve v) unit vector + - along traverse (towards +ve w) unit vector + ''' + p, normal, vec_v, vec_w = m.h.details(**m._vw2tiu_kw(v,w)) + if w > m.nt: + normal = -normal + vec_w = -vec_w + return p, normal, vec_v, vec_w