Changeset 6187


Ignore:
Timestamp:
Jan 17, 2009, 3:32:16 PM (15 years ago)
Author:
ole
Message:

Reversed loops in interpolate_polyline to simplify

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/interpolate.py

    r6186 r6187  
    579579    """Auxiliary function used by interpolate_polyline
    580580    """
    581    
    582     for i in range(number_of_points):
    583 
    584         x2, y2 = point_coordinates[i,:]
    585         found = False
    586    
    587         for j in range(number_of_nodes):           
     581
     582    for j in range(number_of_nodes):               
     583        neighbour_id = gauge_neighbour_id[j]
     584       
     585       
     586        if neighbour_id >= 0:
     587            x0, y0 = polyline_nodes[j,:]
     588            x1, y1 = polyline_nodes[neighbour_id,:]
    588589           
    589             neighbour_id = gauge_neighbour_id[j]
    590             if neighbour_id >= 0:
    591                 x0, y0 = polyline_nodes[j,:]
    592                 x1, y1 = polyline_nodes[neighbour_id,:]
     590            segment_len = sqrt((x1-x0)**2 + (y1-y0)**2)
     591            segment_delta = f[neighbour_id] - f[j]           
     592            slope = segment_delta/segment_len
    593593           
     594               
     595            for i in range(number_of_points):               
     596               
     597                x2, y2 = point_coordinates[i,:]
    594598                if point_on_line([x2, y2],
    595599                                 [[x0, y0], [x1, y1]],
    596600                                 rtol=1.0e-6):
    597601                                 
    598                     found = True
    599                     segment_len = sqrt((x1-x0)**2 + (y1-y0)**2)
     602
    600603                    dist = sqrt((x2-x0)**2 + (y2-y0)**2)
    601                     z[i] = (f[neighbour_id] - f[j])*dist/segment_len + f[j]
    602                     break
    603                                  
    604         if not found:
    605             z[i] = 0.0               
     604                    z[i] = slope*dist + f[j]
     605     
     606
    606607       
    607608       
Note: See TracChangeset for help on using the changeset viewer.