Changeset 2508 for inundation/utilities/numerical_tools.py
- Timestamp:
- Mar 9, 2006, 12:25:31 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/utilities/numerical_tools.py
r2040 r2508 124 124 125 125 126 #################################################################### 127 #Python versions of function that are also implemented in numerical_tools_ext.c 128 # 129 130 def gradient_python(x0, y0, x1, y1, x2, y2, q0, q1, q2): 131 """ 132 """ 133 134 det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0) 135 a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0) 136 a /= det 137 138 b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0) 139 b /= det 140 141 return a, b 142 143 144 def gradient2_python(x0, y0, x1, y1, q0, q1): 145 """Compute radient based on two points and enforce zero gradient 146 in the direction orthogonal to (x1-x0), (y1-y0) 147 """ 148 149 #Old code 150 #det = x0*y1 - x1*y0 151 #if det != 0.0: 152 # a = (y1*q0 - y0*q1)/det 153 # b = (x0*q1 - x1*q0)/det 154 155 #Correct code (ON) 156 det = (x1-x0)**2 + (y1-y0)**2 157 if det != 0.0: 158 a = (x1-x0)*(q1-q0)/det 159 b = (y1-y0)*(q1-q0)/det 160 161 return a, b 162 163 164 ############################################## 165 #Initialise module 166 167 from utilities import compile 168 if compile.can_use_C_extension('util_ext.c'): 169 from util_ext import gradient, gradient2#, point_on_line 170 else: 171 gradient = gradient_python 172 gradient2 = gradient2_python 173 174 175 if __name__ == "__main__": 176 pass 177
Note: See TracChangeset
for help on using the changeset viewer.