1*19978Sdist /* 2*19978Sdist * Copyright (c) 1980 Regents of the University of California. 3*19978Sdist * All rights reserved. The Berkeley software License Agreement 4*19978Sdist * specifies the terms and conditions for redistribution. 5*19978Sdist */ 6*19978Sdist 715462Sralph #ifndef lint 8*19978Sdist static char sccsid[] = "@(#)arc.c 5.1 (Berkeley) 05/07/85"; 9*19978Sdist #endif not lint 1015462Sralph 1115462Sralph #include "hp7221.h" 1215462Sralph 1315462Sralph /* 1415462Sralph * 7221 requires knowing the anlge of arc. To do this, the triangle formula 1515462Sralph * c^2 = a^2 + b^2 - 2*a*b*cos(angle) 1615462Sralph * is used where "a" and "b" are the radius of the circle and "c" is the 1715462Sralph * distance between the beginning point and the end point. 1815462Sralph * 1915462Sralph * This gives us "angle" or angle - 180. To find out which, draw a line from 2015462Sralph * beg to center. This splits the plane in half. All points on one side of the 2115462Sralph * plane will have the same sign when plugged into the equation for the line. 2215462Sralph * Pick a point on the "right side" of the line (see program below). If "end" 2315462Sralph * has the same sign as this point does, then they are both on the same side 2415462Sralph * of the line and so angle is < 180. Otherwise, angle > 180. 2515462Sralph */ 2615462Sralph 2715462Sralph #define side(x,y) (a*(x)+b*(y)+c > 0.0 ? 1 : -1) 2815462Sralph 2915462Sralph arc(xcent,ycent,xbeg,ybeg,xend,yend) 3015462Sralph int xcent,ycent,xbeg,ybeg,xend,yend; 3115462Sralph { 3215462Sralph double radius2, c2; 3315462Sralph double a,b,c; 3415462Sralph int angle; 3515462Sralph 3615462Sralph /* Probably should check that this is really a circular arc. */ 3715462Sralph radius2 = (xcent-xbeg)*(xcent-xbeg) + (ycent-ybeg)*(ycent-ybeg); 3815462Sralph c2 = (xend-xbeg)*(xend-xbeg) + (yend-ybeg)*(yend-ybeg); 3915462Sralph angle = (int) ( 180.0/PI * acos(1.0 - c2/(2.0*radius2)) + 0.5 ); 4015462Sralph 4115462Sralph a = (double) (ycent - ybeg); 4215462Sralph b = (double) (xcent - xbeg); 4315462Sralph c = (double) (ycent*xbeg - xcent*ybeg); 4415462Sralph if (side(xbeg + (ycent-ybeg), ybeg - (xcent-xbeg)) != side(xend,yend)) 4515462Sralph angle += 180; 4615462Sralph 4715462Sralph move(xcent, ycent); 4815462Sralph /* Not quite implemented... 4915462Sralph printf("C(A%d c)[%d,%d]", angle, xbeg, ybeg); 5015462Sralph */ 5115462Sralph } 52