Ignore:
Timestamp:
Mar 12, 2006, 9:25:40 PM (18 years ago)
Author:
ole
Message:

Moved more general numerical functionality into utilities/numerical_tools.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/util.py

    r2516 r2526  
    88import utilities.polygon
    99from warnings import warn
    10 
    11 
    12 def angle(v):
    13     """Compute angle between e1 (the unit vector in the x-direction)
    14     and the specified vector
    15     """
    16 
    17     from math import acos, pi, sqrt
    18     from Numeric import sum, array
    19 
    20     l = sqrt( sum (array(v)**2))
    21     v1 = v[0]/l
    22     v2 = v[1]/l
    23 
    24 
    25     theta = acos(v1)
    26    
    27     #try:
    28     #   theta = acos(v1)
    29     #except ValueError, e:
    30     #    print 'WARNING (util.py): Angle acos(%s) failed: %s' %(str(v1), e)
    31     #
    32     #    #FIXME, hack to avoid acos(1.0) Value error
    33     #    # why is it happening?
    34     #    # is it catching something we should avoid?
    35     #    #FIXME (Ole): When did this happen? We need a unit test to
    36     #    #reveal this condition or otherwise remove the hack
    37     #   
    38     #    s = 1e-6
    39     #    if (v1+s >  1.0) and (v1-s < 1.0) :
    40     #        theta = 0.0
    41     #    elif (v1+s >  -1.0) and (v1-s < -1.0):
    42     #        theta = 3.1415926535897931
    43     #    print 'WARNING (util.py): angle v1 is %f, setting acos to %f '\
    44     #          %(v1, theta)
    45 
    46     if v2 < 0:
    47         #Quadrant 3 or 4
    48         theta = 2*pi-theta
    49 
    50     return theta
    51 
    52 
    53 def anglediff(v0, v1):
    54     """Compute difference between angle of vector x0, y0 and x1, y1.
    55     This is used for determining the ordering of vertices,
    56     e.g. for checking if they are counter clockwise.
    57 
    58     Always return a positive value
    59     """
    60 
    61     from math import pi
    62 
    63     a0 = angle(v0)
    64     a1 = angle(v1)
    65 
    66     #Ensure that difference will be positive
    67     if a0 < a1:
    68         a0 += 2*pi
    69 
    70     return a0-a1
    71 
    72 
    73 def mean(x):
    74     from Numeric import sum
    75     return sum(x)/len(x)
    76 
    7710
    7811
     
    465398
    466399
     400def angle(v):
     401    """Temporary Interface to new location"""
     402
     403    import utilities.numerical_tools as NT     
     404   
     405    msg = 'angle has moved from util.py.  '
     406    msg += 'Please use "from utilities.numerical_tools import angle"'
     407    warn(msg, DeprecationWarning)
     408
     409    return NT.angle(v)
     410   
     411def anglediff(v0, v1):
     412    """Temporary Interface to new location"""
     413
     414    import utilities.numerical_tools as NT
     415   
     416    msg = 'anglediff has moved from util.py.  '
     417    msg += 'Please use "from utilities.numerical_tools import anglediff"'
     418    warn(msg, DeprecationWarning)
     419
     420    return NT.anglediff(v0, v1)   
     421
     422   
     423def mean(x):
     424    """Temporary Interface to new location"""
     425
     426    import utilities.numerical_tools as NT   
     427   
     428    msg = 'mean has moved from util.py.  '
     429    msg += 'Please use "from utilities.numerical_tools import mean"'
     430    warn(msg, DeprecationWarning)
     431
     432    return NT.mean(x)   
     433
    467434def point_on_line(*args, **kwargs):
    468435    """Temporary Interface to new location"""
Note: See TracChangeset for help on using the changeset viewer.