xref: /csrg-svn/lib/libplot/hp2648/arc.c (revision 15445)
1*15445Sralph #ifndef lint
2*15445Sralph static char sccsid[] = "@(#)arc.c	4.1 (Berkeley) 11/10/83";
3*15445Sralph #endif
4*15445Sralph 
5*15445Sralph #include "hp2648.h"
6*15445Sralph 
7*15445Sralph arc(xcent,ycent,xbeg,ybeg,xend,yend)
8*15445Sralph int xcent,ycent,xbeg,ybeg,xend,yend;
9*15445Sralph {
10*15445Sralph 	double costheta,sintheta,x,y,xn,r;
11*15445Sralph 	double x1,y1,x2,y2;
12*15445Sralph 	int xi,yi,crosspflag,crossp;
13*15445Sralph 
14*15445Sralph 	r = (xcent-xbeg)*(xcent-xbeg)+(ycent-ybeg)*(ycent-ybeg);
15*15445Sralph 	r = pow(r,0.5);
16*15445Sralph 	if(r<1){
17*15445Sralph 		point(xcent,ycent);
18*15445Sralph 		return;
19*15445Sralph 	}
20*15445Sralph 	sintheta = 1.0/r;
21*15445Sralph 	costheta = pow(1-sintheta*sintheta,0.5);
22*15445Sralph 	xi = x = xbeg-xcent;
23*15445Sralph 	yi = y = ybeg-ycent;
24*15445Sralph 	x1 = xcent;
25*15445Sralph 	y1 = ycent;
26*15445Sralph 	x2 = xend;
27*15445Sralph 	y2 = yend;
28*15445Sralph 	crosspflag = 0;
29*15445Sralph 	do {
30*15445Sralph 		crossp = cross_product(x1,y1,x2,y2,x,y);
31*15445Sralph 		if(crossp >0 && crosspflag == 0) crosspflag = 1;
32*15445Sralph 		point(xcent+xi,ycent+yi);
33*15445Sralph 		xn = x;
34*15445Sralph 		xi = x = x*costheta + y*sintheta;
35*15445Sralph 		yi = y = y*costheta - xn*sintheta;
36*15445Sralph 	} while( crosspflag == 0 || crossp >0);
37*15445Sralph }
38*15445Sralph 
39*15445Sralph cross_product(x1,y1,x2,y2,x3,y3)
40*15445Sralph double x1,x2,x3,y1,y2,y3;
41*15445Sralph {
42*15445Sralph 	double z,a,b;
43*15445Sralph 	a = (y3-y2)*(x2-x1);
44*15445Sralph 	b = (x3-x2)*(y2-y1);
45*15445Sralph 	z = a-b;
46*15445Sralph 	if(z<0) return(-1);
47*15445Sralph 	if(z>0) return(1);
48*15445Sralph 	return(0);
49*15445Sralph }
50