!for pt_in_poly_ray_method_* !Find # of poly's endv_poly=-99 !flag npoly=1 firstv_poly(npoly)=1 !1st vertex i=2 !starting vertex for searching do j=firstv_poly(npoly) rl=(xpoly(i)-xpoly(j))**2+(ypoly(i)-ypoly(j))**2 if(rlnvertices) exit enddo !i !print*, npoly,' polygons found' do i=1,npoly if(endv_poly(i)<=0) then write(11,*)'pt_in_poly: end not closed, ',i,firstv_poly(i) stop endif if(endv_poly(i)xmax.or.ytestymax) then !outside in_out=-1; inters=-1 return endif an2=ray_angle/180*pi cosa=cos(an2); sina=sin(an2) loop1: do i=1,npoly do j=firstv_poly(i),endv_poly(i)-1 j2=j+1 !Calc intersection btw 2 lines: !L1: x=x_0+(cos,sin)*t1 (t1>=0) (x_0 is the test pt) !L2: x=x_1+(x_2-x_1)*t2 (0<=t2<=1) (x_{1,2} are side pts) x0=xtest; y0=ytest x1=xpoly(j); x2=xpoly(j2) y1=ypoly(j); y2=ypoly(j2) delta=(y1-y2)*cosa-(x1-x2)*sina if(delta==0) then write(11,*)'pt_in_poly, delta=0:',i,j,delta stop endif t1=((x1-x0)*(y1-y2)-(y1-y0)*(x1-x2))/delta t2=((y1-y0)*cosa-(x1-x0)*sina)/delta if(t2>=0.and.t2<=1) then if(abs(t1)0) then if(t2==0.or.t2==1) then !ambiguous intersection (with at least 2 sides) write(11,*)'pt_in_poly: plz adjust ray_angle:',i,j,t1,t2 stop endif !Exactly 1 intersection in_out=-in_out inters=inters+1 !Debug !xin=x0+cosa*t1 !yin=y0+sina*t1 !write(98,*)inters,real(xin),real(yin),i,j,j2 endif endif !t2 enddo !j end do loop1 !i=1,npoly