def curvature_maxima(self):
   """Return a sorted tuple of 'Angle' objects representing the
      parameters where the 'Ovoid' curvature has a local maximum."""
   angles=[Angle(i,'deg') for i in xrange(-170,185,10)]
   k=self._path.kappa; f=Function(self._path.kappa_p1,self._path.kappa_p2)
   positions=[round(k(a),15) for a in angles]
   maxima=[angles[i] for i,p in enumerate(positions) \
             if p>positions[i-1] and p>positions[(i+1)%36]]
   return sorted(Angle(f.root(g.rad),'rad') for g in maxima)
Beispiel #2
0
 def gauge(self):
   """Get a sequence of SVG use statements representing the gauge."""
   g=Group(Key("gauge")); uk=Key("part")
   spr = [d for d in self._defs if d.key.count("splice")>0][0]
   sr = [d for d in self._defs if d.key.count("section")>0][0]
   hr = [d for d in self._defs if d.key.count("hairpin")>0][0]
   a=Angle(2.0*self.angle,'deg'); m=self._n>>1
   if odd(m):
     cp=m+1>>1; cm=cp-1
     u=Use(hr,uk); u.xform=Transform(rotate=-a*cm); g+=u
     u=Use(spr,uk); u.xform=Transform(rotate=-a*cm+a/2.0); g+=u
   else:
     cp=cm=m>>1; u=Use(hr,uk); u.xform=Transform(rotate=-a*cm); g+=u
   for i in range(-cm+1,0):
     if odd(i):
       u=Use(sr,uk); u.xform=Transform(rotate=a*i); g+=u
     else:
       u=Use(hr,uk); u.xform=Transform(rotate=a*i); g+=u
   for i in range(1,cp):
     if odd(i):
       u=Use(sr,uk); u.xform=Transform(rotate=a*i); g+=u
     else:
       u=Use(hr,uk); u.xform=Transform(rotate=a*i); g+=u
   hr = [d for d in self._defs if d.key.count("header")>0][0]
   z=C(0.0,-(self._ir+self._or)/2.0)*C(-self._a/1.618)
   u=Use(hr,uk); u.xform=Transform(translate=z); g+=u
   return g
Beispiel #3
0
  def __init__(self,angle,area):
    """Fillet in a polygon corner defined by two edges separated by 'Angle'
       object 'angle', such that the opposite vertex is an arc center, such
       that '180-angle.deg' spans the arc.  Arc tangency implies the remaining
       two angles are 90 degrees, and the opposing edges are orthogonal to
       the implied edges of the given 'angle'.

       'area' is the area of the fillet in the corner."""
    self._a,self._da = Angle(angle),abs(float(area)) # sanitize
Beispiel #4
0
 def section(self):
   """Get an svg.dom.Group representing a hairpin and two splices."""
   g=Group(Key("section")); uk=Key("trace")
   sr = [d for d in self._defs if d.key.count("splice")>0][0]
   hr = [d for d in self._defs if d.key.count("hairpin")>0][0]
   a=Angle(self.angle,'deg')
   u=Use(sr,uk); u.xform=Transform(rotate=-a); g+=u
   u=Use(hr,uk); g+=u
   u=Use(sr,uk); u.xform=Transform(rotate= a); g+=u
   return g
Beispiel #5
0
 def __init__(self,radius=.05,clearance=0.03):
   """The 'SqPin' object origin is the pin center.  The pad is a circle of
      radius in inches with two flats so that there is 'clearance'
      inches between adjacent pads on a header.  The pin is a
      .64 mm square (~.025")."""
   super(SqPin,self).__init__(Key("sqpin"))
   self._cl,self._r = map(float,[clearance,radius])
   p,s = Path(Key("pad")),Rectangle(C(0.32,0.32),key=Key("pin"))
   self+=p; self+=s
   p.fill,p.stroke = "Chocolate","none"
   s.fill,s.stroke = "Gold","none"
   r,c = self._r*25.4,self._cl*25.4
   a=Angle(acos((r-c/2.0)/r),'rad'); v=r*C(a)
   p.move(-v); p.arc(r,-~v,False); p.line(v); p.arc(r,~v,False); p.line(-v)
Beispiel #6
0
 def __call__(self,index,proportion):
   """Return a tuple of 'Fillet' properties of the O-ring pressed into
      triangle corner 'index' - an index into the initialization vertices.
      The area of the open 'Fillet' will be a 'proportion' of the difference
      between the area of the triangle and the O-ring section.  The tuple
      returned is:
        (radius,edge,vertex[index],tangent_0,center,tangent_1)"""
   i,p = abs(int(index)%3),min(abs(float(proportion)),1.0) # sanitize
   pts=self._v; v=pts[i]
   a=acos( (pts[(i-1)%3]-v).unit|(pts[(i+1)%3]-v).unit) # arg is inner product
   f=Fillet(Angle(a,'rad'),self._da*p)
   r,e = f.radius,f.edge
   du=(pts[(i-1)%3]-v).unit; dv=du.ortho
   t0=v+e*du; c=t0+r*dv
   t1=v+e*(pts[(i+1)%3]-v).unit
   ret=map(_tidy,[r,e,v,t0,c,t1])
   return tuple( [ret[0].x,ret[1].x]+ret[2:] )
Beispiel #7
0
 def __init__(self,IR,OR,trace=.25,radius=.75):
   """'IR' is the inside radius of the available annulus for gauge wires
      and 'OR' is the outside radius.  The gauge pattern will provide a
      minimum clearance for 'trace' width gauge wires of distance 'radius'
      within that annulus.  The value 'radius' is also the radius of turns
      in the pattern."""
   super(Gauge,self).__init__(Key("assembly"))
   self._ir,self._or,self._w,self._r = map(float,[IR,OR,trace,radius]) # sanitize
   self._cr=self._ir+2.0*self._r+self._w  # minimum center radius
   self._n=int(pi/asin(self._r/self._cr)) # number of radial traces that fit
   self._n += 1 if odd(self._n) else 2    # normalize
   self._a=Angle(1.0/self._n)             # half angle between traces
   self._cr=self._r/sin(self._a.rad)      # adjusted center radius
   self._tr=self._or-self._r-.5*self._w   # outside trace radius
   self._defs=d=Defs()
   self+=d; d+=self.hairpin; d+=self.splice; d+=self.section
   sqp=SqPin(); d+=sqp; hdr=Header(sqp); hdr.xform=Transform(rotate=-4.0*self._a)
   d+=hdr; d+=self.gauge; d+=self.inside_sensor; d+=self.outside_sensor
Beispiel #8
0
 def __call__(self, alpha):
     """Interpolate a position on the arc:
       'alpha'     return
     --------------------
        -1.0       'p2'
    -1.0> & >0.0   position on circular arc excluding 'p1',
                   linear in anglular deviation.
         0.0       'p0'
     0.0< & <1.0   position on circular arc containing 'p1',
                   linear in angular deviation.
         1.0       'p2'
    Values outside the range are converted to the corresponding
    cyclic modulus inside the range."""
     a = Angle(float(alpha))  # sanitize
     c, da = self.center, t * self._a / 2.0
     q = Q(cos(da.rad),
           sin(da.rad) * self.W).unit
     return c + q(self._args[0] - c)
Beispiel #9
0
 def skewY(self,a):
   """Push a skew of the x coordinate by angle 'a' in degrees
      on the transform list."""
   a=Angle(a,'deg'); t=tan(a.rad)
   self._stack.append( \
       ('y',a.deg,Matrix(row1=(t,1.0,0.0)) ) )
Beispiel #10
0
 def rotate(self,a):
   """Push a rotation by angle 'a' in degrees on the transform list."""
   a=Angle(a,'deg'); z=a.unit; c,s = z
   self._stack.append( \
       ('r',a.deg,Matrix((c,-s,0.0),(s,c,0.0)) ) )
Beispiel #11
0
 def angle(self):
     """Get an 'Angle' object representing the angle subtended by the 'Arc'."""
     if self._a is not None: return self._a
     p0, p1, p2 = self._args
     c = self.center
     self._a = Angle(acos(p0 - c | p2 - c), 'rad')
Beispiel #12
0
 def tangent(self, angle=Angle(0.0)):
     """Return the unit tangent at 'Angle' object 'angle' from the reference
    position self.vertex in the direction of 'p1' used to create the
    circle."""
     return self._f(C(angle + Angle(.5))) - self.center
Beispiel #13
0
 def __repr__(self):
     """Return a string showing internal representation."""
     d, p, c = self.tangent(Angle(0.0)), self._ref, self._c
     return self.__class__.__name__+"({!r},{!r},{!r})".format( \
                               d.clean,self._ref.clean,c.clean )