1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)arc.c	5.1 (Berkeley) 5/7/85";
   9: #endif not lint
  10: 
  11: #include "hp7221.h"
  12: 
  13: /*
  14:  * 7221 requires knowing the anlge of arc.  To do this, the triangle formula
  15:  *	c^2 = a^2 + b^2 - 2*a*b*cos(angle)
  16:  * is used where "a" and "b" are the radius of the circle and "c" is the
  17:  * distance between the beginning point and the end point.
  18:  *
  19:  * This gives us "angle" or angle - 180.  To find out which, draw a line from
  20:  * beg to center.  This splits the plane in half.  All points on one side of the
  21:  * plane will have the same sign when plugged into the equation for the line.
  22:  * Pick a point on the "right side" of the line (see program below).  If "end"
  23:  * has the same sign as this point does, then they are both on the same side
  24:  * of the line and so angle is < 180.  Otherwise, angle > 180.
  25:  */
  26: 
  27: #define side(x,y)   (a*(x)+b*(y)+c > 0.0 ? 1 : -1)
  28: 
  29: arc(xcent,ycent,xbeg,ybeg,xend,yend)
  30: int xcent,ycent,xbeg,ybeg,xend,yend;
  31: {
  32:     double radius2, c2;
  33:     double a,b,c;
  34:     int angle;
  35: 
  36:     /* Probably should check that this is really a circular arc.  */
  37:     radius2 = (xcent-xbeg)*(xcent-xbeg) + (ycent-ybeg)*(ycent-ybeg);
  38:     c2 = (xend-xbeg)*(xend-xbeg) + (yend-ybeg)*(yend-ybeg);
  39:     angle = (int) ( 180.0/PI * acos(1.0 - c2/(2.0*radius2)) + 0.5 );
  40: 
  41:     a = (double) (ycent - ybeg);
  42:     b = (double) (xcent - xbeg);
  43:     c = (double) (ycent*xbeg - xcent*ybeg);
  44:     if (side(xbeg + (ycent-ybeg), ybeg - (xcent-xbeg)) != side(xend,yend))
  45:         angle += 180;
  46: 
  47:     move(xcent, ycent);
  48:     /* Not quite implemented...
  49: 	printf("C(A%d c)[%d,%d]", angle, xbeg, ybeg);
  50: 	*/
  51: }

Defined functions

arc defined in line 29; never used

Defined variables

sccsid defined in line 8; never used

Defined macros

side defined in line 27; used 2 times
  • in line 44(2)
Last modified: 1985-05-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 830
Valid CSS Valid XHTML 1.0 Strict