Ignore:
Timestamp:
May 31, 2005, 2:24:14 PM (20 years ago)
Author:
ole
Message:

Applyed new formula for computing gradients for triangles that have only one neighbour (thanks to Matt for pointing out the bug) and added unit tests as appropriate.
See util_ext.c for documentation of the derivation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/util_ext.h

    r1137 r1486  
    4747  *b /= det;
    4848
     49  return 0;
     50}
     51
     52
     53int _gradient2(double x0, double y0,
     54               double x1, double y1,
     55               double q0, double q1,
     56               double *a, double *b) {
     57  /*Compute gradient (a,b) between two points (x0,y0) and (x1,y1)
     58  with values q0 and q1 such that the plane is constant in the direction
     59  orthogonal to (x1-x0, y1-y0).
     60 
     61  Extrapolation formula
     62    q(x,y) = q0 + a*(x-x0) + b*(y-y0)                    (1)
     63 
     64  Substituting the known values for q1 into (1) yields an
     65  under determined  equation for a and b
     66      q1-q0 = a*(x1-x0) + b*(y1-y0)                      (2)
     67     
     68     
     69  Now add the additional requirement that the gradient in the direction
     70  orthogonal to (x1-x0, y1-y0) should be zero. The orthogonal direction
     71  is given by the vector (y0-y1, x1-x0).
     72 
     73  Define the point (x2, y2) = (x0 + y0-y1, y0 + x1-x0) on the orthognal line.
     74  Then we know that the corresponding value q2 should be equal to q0 in order
     75  to obtain the zero gradient, hence applying (1) again   
     76      q0 = q2 = q(x2, y2) = q0 + a*(x2-x0) + b*(y2-y0)
     77                          = q0 + a*(x0 + y0-y1-x0) + b*(y0 + x1-x0 - y0)
     78                          = q0 + a*(y0-y1) + b*(x1-x0)
     79                         
     80  leads to the orthogonality constraint
     81     a*(y0-y1) + b*(x1-x0) = 0                           (3)
     82     
     83  which closes the system and yields
     84 
     85  /               \  /   \   /       \ 
     86  |  x1-x0  y1-y0 |  | a |   | q1-q0 |
     87  |               |  |   | = |       |
     88  |  y0-y1  x1-x0 |  | b |   |   0   |
     89  \               /  \   /   \       /
     90   
     91  which is solved using the standard determinant technique   
     92     
     93  */
     94
     95  double det, xx, yy, qq;
     96 
     97  xx = x1-x0;
     98  yy = y1-y0;
     99  qq = q1-q0;
     100   
     101  det = xx*xx + yy*yy;  //FIXME  catch det == 0
     102  *a = xx*qq/det;
     103  *b = yy*qq/det;
     104       
    49105  return 0;
    50106}
Note: See TracChangeset for help on using the changeset viewer.