chiark / gitweb /
introduce MoebiusHalf.details (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 6 Nov 2017 13:51:35 +0000 (13:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 6 Nov 2017 13:51:35 +0000 (13:51 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
moebius.py

index ae55a3a74b8843b4e8d4a96bab7c966aa0a9d4a0..4b8d640c5240f8b04a3ecf460d4238239f925b37 100644 (file)
@@ -114,27 +114,33 @@ class MoebiusHalf:
     '''
     return np.array(m._beziers[iu].point_at_t(t))
 
-  def normal(m, iu, t):
-    '''at the top (iu=t=0), is +ve in the +ve y direction'''
+  def details(m, iu, t):
+    '''
+    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 traverse (towards +ve t)                   unit vector
+    '''
+    if iu == m.nu:
+      return m.details(0, t)
     p = m.point(iu, t)
+    vec_t = unit_v( m.point(iu, t + 0.01) - p )
     if t == 0:
-      dirn = m.edge.dirn(m._thetas[iu], extra_zeta=-tau/4)
-    elif iu == m.nu:
-      return m.normal(0, t)
+      normal = m.edge.dirn(m._thetas[iu], extra_zeta=-tau/4)
+      vec_u = np.cross(vec_t, normal)
     else:
-      vec_t = m.point(iu,   t + 0.01) - p
-      vec_u = m.point(iu+1, t)        - p
-      dirn =  np.cross(vec_u, vec_t)
-      dirn = unit_v(dirn)
-    return dirn
+      vec_u = unit_v( m.point(iu+1, t) - p )
+      normal = np.cross(vec_u, vec_t)
+    return (p, normal, vec_u, vec_t)
 
   def point_offset(m, iu, t, offset):
     '''
     offset by offset perpendicular to the surface
      at the top (iu=t=0), +ve offset is in the +ve y direction
     '''
-    p = m.point(iu, t)
-    return p + offset * m.normal(iu, t)
+    p, normal, dummy, dummy = m.details(iu, t)
+    return p + offset * normal
 
 class Moebius():
   def __init__(m, nv, nw):