148517Sbostic /*-
2*61393Sbostic * Copyright (c) 1980, 1993
3*61393Sbostic * The Regents of the University of California. All rights reserved.
448517Sbostic *
548517Sbostic * %sccs.include.proprietary.c%
619975Sdist */
719975Sdist
815445Sralph #ifndef lint
9*61393Sbostic static char sccsid[] = "@(#)arc.c 8.1 (Berkeley) 06/04/93";
1048517Sbostic #endif /* not lint */
1115445Sralph
1215445Sralph #include "hp2648.h"
1315445Sralph
arc(xcent,ycent,xbeg,ybeg,xend,yend)1415445Sralph arc(xcent,ycent,xbeg,ybeg,xend,yend)
1515445Sralph int xcent,ycent,xbeg,ybeg,xend,yend;
1615445Sralph {
1715445Sralph double costheta,sintheta,x,y,xn,r;
1815445Sralph double x1,y1,x2,y2;
1915445Sralph int xi,yi,crosspflag,crossp;
2015445Sralph
2115445Sralph r = (xcent-xbeg)*(xcent-xbeg)+(ycent-ybeg)*(ycent-ybeg);
2215445Sralph r = pow(r,0.5);
2315445Sralph if(r<1){
2415445Sralph point(xcent,ycent);
2515445Sralph return;
2615445Sralph }
2715445Sralph sintheta = 1.0/r;
2815445Sralph costheta = pow(1-sintheta*sintheta,0.5);
2915445Sralph xi = x = xbeg-xcent;
3015445Sralph yi = y = ybeg-ycent;
3115445Sralph x1 = xcent;
3215445Sralph y1 = ycent;
3315445Sralph x2 = xend;
3415445Sralph y2 = yend;
3515445Sralph crosspflag = 0;
3615445Sralph do {
3715445Sralph crossp = cross_product(x1,y1,x2,y2,x,y);
3815445Sralph if(crossp >0 && crosspflag == 0) crosspflag = 1;
3915445Sralph point(xcent+xi,ycent+yi);
4015445Sralph xn = x;
4115445Sralph xi = x = x*costheta + y*sintheta;
4215445Sralph yi = y = y*costheta - xn*sintheta;
4315445Sralph } while( crosspflag == 0 || crossp >0);
4415445Sralph }
4515445Sralph
cross_product(x1,y1,x2,y2,x3,y3)4615445Sralph cross_product(x1,y1,x2,y2,x3,y3)
4715445Sralph double x1,x2,x3,y1,y2,y3;
4815445Sralph {
4915445Sralph double z,a,b;
5015445Sralph a = (y3-y2)*(x2-x1);
5115445Sralph b = (x3-x2)*(y2-y1);
5215445Sralph z = a-b;
5315445Sralph if(z<0) return(-1);
5415445Sralph if(z>0) return(1);
5515445Sralph return(0);
5615445Sralph }
57