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