Changeset 5321 for anuga_core/source/anuga/utilities/polygon_ext.c
- Timestamp:
- May 14, 2008, 2:25:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/polygon_ext.c
r5225 r5321 58 58 } 59 59 60 61 62 /* 63 WORK IN PROGRESS TO OPTIMISE INTERSECTION 64 int __intersection(double x0, double y0, 65 double x1, double y1) { 66 67 68 x0 = line0[0,0]; y0 = line0[0,1] 69 x1 = line0[1,0]; y1 = line0[1,1] 70 71 x2 = line1[0,0]; y2 = line1[0,1] 72 x3 = line1[1,0]; y3 = line1[1,1] 73 74 denom = (y3-y2)*(x1-x0) - (x3-x2)*(y1-y0) 75 u0 = (x3-x2)*(y0-y2) - (y3-y2)*(x0-x2) 76 u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0) 77 78 if allclose(denom, 0.0): 79 # Lines are parallel - check if they coincide on a shared a segment 80 81 if allclose( [u0, u1], 0.0 ): 82 # We now know that the lines if continued coincide 83 # The remaining check will establish if the finite lines share a segment 84 85 line0_starts_on_line1 = line0_ends_on_line1 =\ 86 line1_starts_on_line0 = line1_ends_on_line0 = False 87 88 if point_on_line([x0, y0], line1): 89 line0_starts_on_line1 = True 90 91 if point_on_line([x1, y1], line1): 92 line0_ends_on_line1 = True 93 94 if point_on_line([x2, y2], line0): 95 line1_starts_on_line0 = True 96 97 if point_on_line([x3, y3], line0): 98 line1_ends_on_line0 = True 99 100 if not(line0_starts_on_line1 or line0_ends_on_line1\ 101 or line1_starts_on_line0 or line1_ends_on_line0): 102 # Lines are parallel and would coincide if extended, but not as they are. 103 return 3, None 104 105 106 # One line fully included in the other. Use direction of included line 107 if line0_starts_on_line1 and line0_ends_on_line1: 108 # Shared segment is line0 fully included in line1 109 segment = array([[x0, y0], [x1, y1]]) 110 111 if line1_starts_on_line0 and line1_ends_on_line0: 112 # Shared segment is line1 fully included in line0 113 segment = array([[x2, y2], [x3, y3]]) 114 115 116 # Overlap with lines are oriented the same way 117 if line0_starts_on_line1 and line1_ends_on_line0: 118 # Shared segment from line0 start to line 1 end 119 segment = array([[x0, y0], [x3, y3]]) 120 121 if line1_starts_on_line0 and line0_ends_on_line1: 122 # Shared segment from line1 start to line 0 end 123 segment = array([[x2, y2], [x1, y1]]) 124 125 126 # Overlap in opposite directions - use direction of line0 127 if line0_starts_on_line1 and line1_starts_on_line0: 128 # Shared segment from line0 start to line 1 end 129 segment = array([[x0, y0], [x2, y2]]) 130 131 if line0_ends_on_line1 and line1_ends_on_line0: 132 # Shared segment from line0 start to line 1 end 133 segment = array([[x3, y3], [x1, y1]]) 134 135 136 return 2, segment 137 else: 138 # Lines are parallel but they do not coincide 139 return 4, None #FIXME (Ole): Add distance here instead of None 140 141 else: 142 # Lines are not parallel or coinciding 143 u0 = u0/denom 144 u1 = u1/denom 145 146 x = x0 + u0*(x1-x0) 147 y = y0 + u0*(y1-y0) 148 149 # Sanity check - can be removed to speed up if needed 150 assert allclose(x, x2 + u1*(x3-x2)) 151 assert allclose(y, y2 + u1*(y3-y2)) 152 153 # Check if point found lies within given line segments 154 if 0.0 <= u0 <= 1.0 and 0.0 <= u1 <= 1.0: 155 # We have intersection 156 157 return 1, array([x, y]) 158 else: 159 # No intersection 160 return 0, None 161 162 163 } 164 */ 60 165 61 166 … … 176 281 177 282 283 /* 284 PyObject *_intersection(PyObject *self, PyObject *args) { 285 // 286 // intersection(x0, y0, x1, y1) 287 // 288 289 double x, y, x0, y0, x1, y1; 290 int res; 291 PyObject *result; 292 293 // Convert Python arguments to C 294 if (!PyArg_ParseTuple(args, "dddddd", &x, &y, &x0, &y0, &x1, &y1)) { 295 PyErr_SetString(PyExc_RuntimeError, 296 "point_on_line could not parse input"); 297 return NULL; 298 } 299 300 301 // Call underlying routine 302 res = __intersection(x, y, x0, y0, x1, y1); 303 304 // Return values a and b 305 result = Py_BuildValue("i", res); 306 return result; 307 } 308 */ 309 178 310 179 311 PyObject *_separate_points_by_polygon(PyObject *self, PyObject *args) { … … 266 398 267 399 {"_point_on_line", _point_on_line, METH_VARARGS, "Print out"}, 400 //{"_intersection", _intersection, METH_VARARGS, "Print out"}, 268 401 {"_separate_points_by_polygon", _separate_points_by_polygon, 269 402 METH_VARARGS, "Print out"},
Note: See TracChangeset
for help on using the changeset viewer.