1 /*- 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)arc.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* not lint */ 11 12 #include "hp2648.h" 13 14 arc(xcent,ycent,xbeg,ybeg,xend,yend) 15 int xcent,ycent,xbeg,ybeg,xend,yend; 16 { 17 double costheta,sintheta,x,y,xn,r; 18 double x1,y1,x2,y2; 19 int xi,yi,crosspflag,crossp; 20 21 r = (xcent-xbeg)*(xcent-xbeg)+(ycent-ybeg)*(ycent-ybeg); 22 r = pow(r,0.5); 23 if(r<1){ 24 point(xcent,ycent); 25 return; 26 } 27 sintheta = 1.0/r; 28 costheta = pow(1-sintheta*sintheta,0.5); 29 xi = x = xbeg-xcent; 30 yi = y = ybeg-ycent; 31 x1 = xcent; 32 y1 = ycent; 33 x2 = xend; 34 y2 = yend; 35 crosspflag = 0; 36 do { 37 crossp = cross_product(x1,y1,x2,y2,x,y); 38 if(crossp >0 && crosspflag == 0) crosspflag = 1; 39 point(xcent+xi,ycent+yi); 40 xn = x; 41 xi = x = x*costheta + y*sintheta; 42 yi = y = y*costheta - xn*sintheta; 43 } while( crosspflag == 0 || crossp >0); 44 } 45 46 cross_product(x1,y1,x2,y2,x3,y3) 47 double x1,x2,x3,y1,y2,y3; 48 { 49 double z,a,b; 50 a = (y3-y2)*(x2-x1); 51 b = (x3-x2)*(y2-y1); 52 z = a-b; 53 if(z<0) return(-1); 54 if(z>0) return(1); 55 return(0); 56 } 57