|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)arc.c 5.1 (Berkeley) 5/7/85"; ! 9: #endif not lint ! 10: ! 11: #include "hp2648.h" ! 12: ! 13: arc(xcent,ycent,xbeg,ybeg,xend,yend) ! 14: int xcent,ycent,xbeg,ybeg,xend,yend; ! 15: { ! 16: double costheta,sintheta,x,y,xn,r; ! 17: double x1,y1,x2,y2; ! 18: int xi,yi,crosspflag,crossp; ! 19: ! 20: r = (xcent-xbeg)*(xcent-xbeg)+(ycent-ybeg)*(ycent-ybeg); ! 21: r = pow(r,0.5); ! 22: if(r<1){ ! 23: point(xcent,ycent); ! 24: return; ! 25: } ! 26: sintheta = 1.0/r; ! 27: costheta = pow(1-sintheta*sintheta,0.5); ! 28: xi = x = xbeg-xcent; ! 29: yi = y = ybeg-ycent; ! 30: x1 = xcent; ! 31: y1 = ycent; ! 32: x2 = xend; ! 33: y2 = yend; ! 34: crosspflag = 0; ! 35: do { ! 36: crossp = cross_product(x1,y1,x2,y2,x,y); ! 37: if(crossp >0 && crosspflag == 0) crosspflag = 1; ! 38: point(xcent+xi,ycent+yi); ! 39: xn = x; ! 40: xi = x = x*costheta + y*sintheta; ! 41: yi = y = y*costheta - xn*sintheta; ! 42: } while( crosspflag == 0 || crossp >0); ! 43: } ! 44: ! 45: cross_product(x1,y1,x2,y2,x3,y3) ! 46: double x1,x2,x3,y1,y2,y3; ! 47: { ! 48: double z,a,b; ! 49: a = (y3-y2)*(x2-x1); ! 50: b = (x3-x2)*(y2-y1); ! 51: z = a-b; ! 52: if(z<0) return(-1); ! 53: if(z>0) return(1); ! 54: return(0); ! 55: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.