Changeset 26709
- Timestamp:
- 12/06/21 06:56:35 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/jl/md/exp.jl
r26629 r26709 136 136 return contours 137 137 end# }}} 138 #ContourToNodes{{{ 139 """ 140 ContourToNodes - Flag points that are in contour 141 142 More doc to come later.... 143 144 Usage: 145 exp=expread(filename) 146 147 # Examples: 148 ```julia-repl 149 julia> exp=expread('domainoutline.exp') 150 ``` 151 152 # Arguments: 153 - filename: the ARGUS file to read 154 """ 155 function ContourToNodes(x::Vector{Float64},y::Vector{Float64},filename::String,edgevalue::Float64) 156 157 #Read input file 158 contours = expread(filename) 159 160 #Initialize output 161 nbpts = length(x) 162 flags = zeros(Bool,nbpts) 163 164 #Loop over contours 165 for c in 1:length(contours) 166 167 #Get current contours 168 contour = contours[c] 169 xp = contour.x 170 yp = contour.y 171 172 #Check that we are within box 173 xmin = minimum(xp); xmax = maximum(xp) 174 ymin = minimum(yp); ymax = maximum(yp) 175 176 #Loop over all points provided 177 for ii in 1:nbpts 178 179 #If this node is already within one of the contours, do not change it 180 if(flags[ii]) continue end 181 182 #Are we within bounds? 183 if(x[ii]<xmin || x[ii]>xmax || y[ii]<ymin || y[ii]>ymax) continue end 184 185 #we are potentially inside... perform pnpoly test 186 flags[ii] = pnpoly(xp, yp, x[ii], y[ii], edgevalue) 187 end 188 end 189 190 return flags 191 end# }}} 192 193 function pnpoly(xp::Vector{Float64},yp::Vector{Float64},x::Float64,y::Float64,edgevalue::Float64) #{{{ 194 195 npol = length(xp) 196 197 #Do we need to test for colinearity? 198 if(edgevalue!=2) 199 i = 1 200 j = npol 201 while(i<=npol) 202 203 n1 = (yp[i]-yp[j])^2 + (xp[i]-xp[j])^2 204 n2 = (y-yp[j])^2 + (x-xp[j])^2 205 206 normp=sqrt(n1*n2) 207 scalar=(yp[i]-yp[j])*(y-yp[j])+(xp[i]-xp[j])*(x-xp[j]) 208 209 if (scalar == normp) 210 if (n2<=n1) 211 return edgevalue 212 end 213 end 214 215 j = i 216 i += 1 217 end 218 end 219 220 #second test : point is neither on a vertex, nor on a side, where is it ? 221 i = 1 222 j = npol 223 c = false 224 while(i<=npol) 225 if (((yp[i]<=y && y<yp[j]) || (yp[j]<=y && y<yp[i])) && 226 (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i])) 227 c = !c 228 end 229 230 j = i 231 i += 1 232 end 233 return c 234 end# }}}
Note:
See TracChangeset
for help on using the changeset viewer.