Changeset 663

Show
Ignore:
Timestamp:
08/19/03 11:38:47 (5 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBRapier/RBRapier/Tools/Geometry/Curves.py

    r662 r663  
    155155 
    156156 
    157     def fromArc(klass, fromxy, toxy, rx=1., ry=1., xrotation=0, largearcflag=False, sweepflag=False, inDegrees=True, **kw): 
     157    def fromArc(klass, fromxy, toxy, rx=1., ry=1., xrotation=0, largeArcFlag=False, sweepFlag=False, inDegrees=True, **kw): 
    158158        """ 
    159159        Derived from SVG Specification: 
     
    165165        toxy = Numeric.asarray(toxy, klass.NumericType) 
    166166        if xrotation: 
    167             x, y = Numeric.dot(klass._RotationMatrix(xrotation), 0.5*(fromxy-toxy)) 
     167            x, y = Numeric.dot(klass._RotationMatrix(-xrotation), 0.5*(fromxy-toxy)) 
    168168        else: 
    169169            x, y = 0.5*(fromxy-toxy) 
    170         x2 = x**2 
    171         y2 = y**2 
    172  
    173         rx2 = rx**2 
    174         ry2 = ry**2 
     170        x2,y2 = x**2, y**2 
     171 
     172        rx2, ry2 = rx**2, ry**2 
    175173        radiscale = x2/rx2 + y2/ry2 
    176174        if radiscale > 1: 
    177175            # ellipse is not big enough... scale it 
    178176            radiscale = Numeric.sqrt(radiscale) 
    179             rx *= radiscale 
    180             ry *= radiscale 
    181             rx2 = rx**2 
    182             ry2 = ry**2 
     177            rx, ry = radiscale*rx, radiscale*ry 
     178            rx2, ry2 = rx**2, ry**2 
    183179 
    184180        tmp = rx2*y2 + ry2*x2 
    185         sign = (largearcflag ^ sweepflag) and 1 or -1 
     181        sign = (largeArcFlag != sweepFlag) and 1 or -1 
    186182        scale = sign * Numeric.sqrt((rx2*ry2-tmp)/tmp) 
    187  
    188         cxP, cyP = scale*rx*y/ry, -scale*ry*x/rx 
     183        cxP, cyP = scale*rx*y/ry, scale*-ry*x/rx 
     184 
    189185        if xrotation: 
    190186            rot = klass._RotTranMatrix(xrotation, (0.5*(fromxy+toxy))) 
    191             center = Numeric.dot(rot, Numeric.asarray([cxP, cyP, 1.], klass.NumericType))[:2] 
    192             center2 = Numeric.asarray([cxP, cyP]) + (0.5*(fromxy+toxy)) 
    193         else: 
    194             center = Numeric.asarray([cxP, cyP]) + (0.5*(fromxy+toxy))[:2] 
     187            center = Numeric.dot(rot, Numeric.asarray([cxP, cyP, 1.], klass.NumericType)) 
     188        else: 
     189            center = Numeric.asarray([cxP, cyP]) + (0.5*(fromxy+toxy)) 
     190        center = center[:2] 
    195191         
    196192        startpt = ((x-cxP)/rx, (y-cyP)/ry) 
    197193        endpt = ((-x-cxP)/rx, (-y-cyP)/ry) 
    198194        startradians = klass._FindAngle((1., 0.), startpt) 
    199         sweepradians = klass._FindAngle(startpt, endpt) 
    200         if sweepflag: 
     195        sweepradians = klass._FindAngle(startpt, endpt) % _2pi 
     196        if sweepFlag: 
    201197            if sweepradians < 0: 
    202198                sweepradians += _2pi 
     
    246242            return Numeric.transpose(ellipse[:-1,:]) 
    247243        else: 
    248             ellipse = Numeric.asarray([rx*Numeric.cos(sweep), ry*Numeric.sin(sweep)], self.NumericType) 
     244            cx, cy = self.GetCenter() 
     245            ellipse = Numeric.asarray([rx*Numeric.cos(sweep)+cx, ry*Numeric.sin(sweep)+cy], self.NumericType) 
    249246            return Numeric.transpose(ellipse) 
    250247 
     
    259256 
    260257    def _RotationMatrix(klass, radians): 
     258        """Count clockwise rotation""" 
    261259        cosr = Numeric.cos(radians) 
    262260        sinr = Numeric.sin(radians) 
    263         return Numeric.asarray([[cosr, sinr],[-sinr, cosr]], klass.NumericType) 
     261        return Numeric.asarray([[cosr, -sinr],[sinr, cosr]], klass.NumericType) 
    264262    _RotationMatrix = classmethod(_RotationMatrix) 
    265263 
    266264    def _RotTranMatrix(klass, radians, (tx, ty)=(0.,0.)): 
     265        """Count clockwise rotation""" 
    267266        cosr = Numeric.cos(radians) 
    268267        sinr = Numeric.sin(radians) 
    269         return Numeric.asarray([[cosr, sinr, tx],[-sinr, cosr, ty], [0., 0., 1.]], klass.NumericType) 
     268        return Numeric.asarray([[cosr, -sinr, tx],[sinr, cosr, ty], [0., 0., 1.]], klass.NumericType) 
    270269    _RotTranMatrix = classmethod(_RotTranMatrix) 
    271270