function triangle(x,y,g,zero,xb,yb,xe,ye) * ======== * Contourlines in a triangle * -------------------------- * ... Coordinates and function values * at triangle vertices: real x(3),y(3),f(3),g(3) * ... Permutations & actions: integer np(3,6),must(27),move(27) logical triangle,first * * ... Save the following: data np,must,move / 18*0 , 27*0 , 27*0 / data first / .true. / * ... Initialize actions & permutations: if(first) then call setup3(np,must,move) first=.false. endif * * ... Case encoding (base 3): more=0 do 10 k=1,3 f(k)=g(k)-zero if(f(k).eq.0.) more=more*3 if(f(k).lt.0.) more=more*3+1 if(f(k).gt.0.) more=more*3+2 10 continue label=must(more+1) * * ... Permutation of (1,2,3) case: keus=move(more+1) x1=x(np(1,keus)) x2=x(np(2,keus)) x3=x(np(3,keus)) y1=y(np(1,keus)) y2=y(np(2,keus)) y3=y(np(3,keus)) f1=f(np(1,keus)) f2=f(np(2,keus)) f3=f(np(3,keus)) xb=x1 xe=x2 yb=y1 ye=y2 * * ... Perform action: triangle=.false. goto (1,2,3,4,5,6),label * * ... Nothing: 1 continue * ... === 3 continue * ... =<< 5 continue * ... <<< return * * ... Line through one side: 2 continue * ... ==< triangle=.true. return * * ... Line through one vertex: 4 continue * ... =<> xe=(f2*x3-f3*x2)/(f2-f3) ye=(f2*y3-f3*y2)/(f2-f3) triangle=.true. return * * ... Line through two sides: 6 continue * ... <<> xb=(f1*x3-f3*x1)/(f1-f3) yb=(f1*y3-f3*y1)/(f1-f3) xe=(f2*x3-f3*x2)/(f2-f3) ye=(f2*y3-f3*y2)/(f2-f3) triangle=.true. return * end