xref: /csrg-svn/lib/libplot/hp2648/arc.c (revision 19975)
1*19975Sdist /*
2*19975Sdist  * Copyright (c) 1980 Regents of the University of California.
3*19975Sdist  * All rights reserved.  The Berkeley software License Agreement
4*19975Sdist  * specifies the terms and conditions for redistribution.
5*19975Sdist  */
6*19975Sdist 
715445Sralph #ifndef lint
8*19975Sdist static char sccsid[] = "@(#)arc.c	5.1 (Berkeley) 05/07/85";
9*19975Sdist #endif not lint
1015445Sralph 
1115445Sralph #include "hp2648.h"
1215445Sralph 
1315445Sralph arc(xcent,ycent,xbeg,ybeg,xend,yend)
1415445Sralph int xcent,ycent,xbeg,ybeg,xend,yend;
1515445Sralph {
1615445Sralph 	double costheta,sintheta,x,y,xn,r;
1715445Sralph 	double x1,y1,x2,y2;
1815445Sralph 	int xi,yi,crosspflag,crossp;
1915445Sralph 
2015445Sralph 	r = (xcent-xbeg)*(xcent-xbeg)+(ycent-ybeg)*(ycent-ybeg);
2115445Sralph 	r = pow(r,0.5);
2215445Sralph 	if(r<1){
2315445Sralph 		point(xcent,ycent);
2415445Sralph 		return;
2515445Sralph 	}
2615445Sralph 	sintheta = 1.0/r;
2715445Sralph 	costheta = pow(1-sintheta*sintheta,0.5);
2815445Sralph 	xi = x = xbeg-xcent;
2915445Sralph 	yi = y = ybeg-ycent;
3015445Sralph 	x1 = xcent;
3115445Sralph 	y1 = ycent;
3215445Sralph 	x2 = xend;
3315445Sralph 	y2 = yend;
3415445Sralph 	crosspflag = 0;
3515445Sralph 	do {
3615445Sralph 		crossp = cross_product(x1,y1,x2,y2,x,y);
3715445Sralph 		if(crossp >0 && crosspflag == 0) crosspflag = 1;
3815445Sralph 		point(xcent+xi,ycent+yi);
3915445Sralph 		xn = x;
4015445Sralph 		xi = x = x*costheta + y*sintheta;
4115445Sralph 		yi = y = y*costheta - xn*sintheta;
4215445Sralph 	} while( crosspflag == 0 || crossp >0);
4315445Sralph }
4415445Sralph 
4515445Sralph cross_product(x1,y1,x2,y2,x3,y3)
4615445Sralph double x1,x2,x3,y1,y2,y3;
4715445Sralph {
4815445Sralph 	double z,a,b;
4915445Sralph 	a = (y3-y2)*(x2-x1);
5015445Sralph 	b = (x3-x2)*(y2-y1);
5115445Sralph 	z = a-b;
5215445Sralph 	if(z<0) return(-1);
5315445Sralph 	if(z>0) return(1);
5415445Sralph 	return(0);
5515445Sralph }
56