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