1*19974Sdist /* 2*19974Sdist * Copyright (c) 1980 Regents of the University of California. 3*19974Sdist * All rights reserved. The Berkeley software License Agreement 4*19974Sdist * specifies the terms and conditions for redistribution. 5*19974Sdist */ 6*19974Sdist 715484Sralph #ifndef lint 8*19974Sdist static char sccsid[] = "@(#)arc.c 5.1 (Berkeley) 05/07/85"; 9*19974Sdist #endif not lint 1015484Sralph 1115484Sralph #include "gigi.h" 1215484Sralph 1315484Sralph /* 1415484Sralph * gigi requires knowing the anlge of arc. To do this, the triangle formula 1515484Sralph * c^2 = a^2 + b^2 - 2*a*b*cos(angle) 1615484Sralph * is used where "a" and "b" are the radius of the circle and "c" is the 1715484Sralph * distance between the beginning point and the end point. 1815484Sralph * 1915484Sralph * This gives us "angle" or angle - 180. To find out which, draw a line from 2015484Sralph * beg to center. This splits the plane in half. All points on one side of the 2115484Sralph * plane will have the same sign when plugged into the equation for the line. 2215484Sralph * Pick a point on the "right side" of the line (see program below). If "end" 2315484Sralph * has the same sign as this point does, then they are both on the same side 2415484Sralph * of the line and so angle is < 180. Otherwise, angle > 180. 2515484Sralph */ 2615484Sralph 2715484Sralph #define side(x,y) (a*(x)+b*(y)+c > 0.0 ? 1 : -1) 2815484Sralph 2915484Sralph arc(xcent,ycent,xbeg,ybeg,xend,yend) 3015484Sralph int xcent,ycent,xbeg,ybeg,xend,yend; 3115484Sralph { 3215484Sralph double radius2, c2; 3315484Sralph double a,b,c; 3415484Sralph int angle; 3515484Sralph 3615484Sralph /* Probably should check that this is really a circular arc. */ 3715484Sralph radius2 = (xcent-xbeg)*(xcent-xbeg) + (ycent-ybeg)*(ycent-ybeg); 3815484Sralph c2 = (xend-xbeg)*(xend-xbeg) + (yend-ybeg)*(yend-ybeg); 3915484Sralph angle = (int) ( 180.0/PI * acos(1.0 - c2/(2.0*radius2)) + 0.5 ); 4015484Sralph 4115484Sralph a = (double) (ycent - ybeg); 4215484Sralph b = (double) (xcent - xbeg); 4315484Sralph c = (double) (ycent*xbeg - xcent*ybeg); 4415484Sralph if (side(xbeg + (ycent-ybeg), ybeg - (xcent-xbeg)) != side(xend,yend)) 4515484Sralph angle += 180; 4615484Sralph 4715484Sralph move(xcent, ycent); 4815484Sralph printf("C(A%d c)[%d,%d]", angle, xbeg, ybeg); 4915484Sralph } 50