Changeset 2526 for inundation/pyvolution/util.py
- Timestamp:
- Mar 12, 2006, 9:25:40 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/util.py
r2516 r2526 8 8 import utilities.polygon 9 9 from 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 vector15 """16 17 from math import acos, pi, sqrt18 from Numeric import sum, array19 20 l = sqrt( sum (array(v)**2))21 v1 = v[0]/l22 v2 = v[1]/l23 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 error33 # # why is it happening?34 # # is it catching something we should avoid?35 # #FIXME (Ole): When did this happen? We need a unit test to36 # #reveal this condition or otherwise remove the hack37 #38 # s = 1e-639 # if (v1+s > 1.0) and (v1-s < 1.0) :40 # theta = 0.041 # elif (v1+s > -1.0) and (v1-s < -1.0):42 # theta = 3.141592653589793143 # print 'WARNING (util.py): angle v1 is %f, setting acos to %f '\44 # %(v1, theta)45 46 if v2 < 0:47 #Quadrant 3 or 448 theta = 2*pi-theta49 50 return theta51 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 value59 """60 61 from math import pi62 63 a0 = angle(v0)64 a1 = angle(v1)65 66 #Ensure that difference will be positive67 if a0 < a1:68 a0 += 2*pi69 70 return a0-a171 72 73 def mean(x):74 from Numeric import sum75 return sum(x)/len(x)76 77 10 78 11 … … 465 398 466 399 400 def 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 411 def 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 423 def 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 467 434 def point_on_line(*args, **kwargs): 468 435 """Temporary Interface to new location"""
Note: See TracChangeset
for help on using the changeset viewer.