plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

rarc.c (954B)


      1 #include "mplot.h"
      2 /*		arc plotting routine		*/
      3 /*		from x1,y1 to x2,y2		*/
      4 /*	with center xc,yc and radius rr	*/
      5 /*	integrates difference equation		*/
      6 /*	negative rr draws counterclockwise	*/
      7 #define PI4 0.7854
      8 void rarc(double x1, double y1, double x2, double y2, double xc, double yc, double rr){
      9 	register double dx, dy, a, b;
     10 	double	ph, dph, rd, xnext;
     11 	register int	n;
     12 	dx = x1 - xc;
     13 	dy = y1 - yc;
     14 	rd = sqrt(dx * dx + dy * dy);
     15 	if (rd / e1->quantum < 1.0) {
     16 		move(xc, yc);
     17 		vec(xc, yc);
     18 		return;
     19 	}
     20 	dph = acos(1.0 - (e1->quantum / rd));
     21 	if (dph > PI4)
     22 		dph = PI4;
     23 	ph=atan2((y2-yc),(x2 - xc)) - atan2(dy, dx);
     24 	if (ph < 0)
     25 		ph += 6.2832;
     26 	if (rr < 0)
     27 		ph = 6.2832 - ph;
     28 	if (ph < dph)
     29 		plotline(x1, y1, x2, y2);
     30 	else {
     31 		n = ph / dph;
     32 		a = cos(dph);
     33 		b = sin(dph);
     34 		if (rr < 0)
     35 			b = -b;
     36 		move(x1, y1);
     37 		while ((n--) >= 0) {
     38 			xnext = dx * a - dy * b;
     39 			dy = dx * b + dy * a;
     40 			dx = xnext;
     41 			vec(dx + xc, dy + yc);
     42 		}
     43 	}
     44 }