r109: reorganized header files
[ctsim.git] / libctgraphics / circle.cpp
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: circle.cpp,v 1.2 2000/06/19 19:04:05 kevin Exp $
6 **  $Log: circle.cpp,v $
7 **  Revision 1.2  2000/06/19 19:04:05  kevin
8 **  reorganized header files
9 **
10 **  Revision 1.1  2000/06/19 18:05:03  kevin
11 **  initial cvs import
12 **
13 **  Revision 1.1  2000/06/13 16:20:31  kevin
14 **  finished c++ conversions
15 **
16 **  Revision 1.2  2000/05/24 22:49:01  kevin
17 **  Updated SGP: first function X-windows version
18 **
19 **  Revision 1.1.1.1  2000/04/28 13:02:44  kevin
20 **  Initial CVS import for first public release
21 **
22 **
23 **
24 **  This program is free software; you can redistribute it and/or modify
25 **  it under the terms of the GNU General Public License (version 2) as
26 **  published by the Free Software Foundation.
27 **
28 **  This program is distributed in the hope that it will be useful,
29 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
30 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 **  GNU General Public License for more details.
32 **
33 **  You should have received a copy of the GNU General Public License
34 **  along with this program; if not, write to the Free Software
35 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
36 ******************************************************************************/
37
38 /* FUNCTION
39  * sgp2_circle - draw circle of radius r at current center              
40  */
41
42 #include "math.h"
43 #include "ctsupport.h"
44 #include "sgp.h"
45
46 void 
47 sgp2_draw_circle (const double r)
48 {
49         sgp2_draw_arc (0.0, 7.0, r);
50 }
51
52 /*==============================================================*/
53 /* draw arc around current center.  pass angles and radius      */
54 /*==============================================================*/
55
56 void 
57 sgp2_draw_arc (double start, double stop, const double r)
58 {
59         double c, s, theta, angle;
60         float x, y, xp, yp;
61
62         if ((stop-start) > 2 * PI)
63             stop = start + 2 * PI;
64         if ((start-stop) > 2 * PI)
65             stop = start + 2 * PI;
66         while (start >= stop)
67             stop += 2*PI;
68
69         x = r * cos ((double) start);
70         y = r * sin ((double) start);
71         sgp2_move_rel (x, y);          /* move from center to start of arc */
72
73         theta = 5 * PI / 180;
74         c = cos(theta);
75         s = sin(theta);
76
77         for (angle = start; angle < stop - theta; angle += theta) {
78             xp = c * x - s * y;
79             yp = s * x + c * y;
80             sgp2_line_rel (xp - x, yp - y);
81             x = xp; y = yp;
82         }
83
84         c = cos (stop - angle);
85         s = sin (stop - angle);
86         xp = c * x - s * y;
87         yp = s * x + c * y;
88         sgp2_line_rel (xp - x, yp - y);
89
90         x = r * cos ((double) stop);
91         y = r * sin ((double) stop);
92         sgp2_move_rel (-x, -y);         /* move back to center of circle */
93 }