|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: fl_arc.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Arc functions for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00033 // Utility for drawing arcs and circles. They are added to 00034 // the current fl_begin/fl_vertex/fl_end path. 00035 // Incremental math implementation: 00036 00037 #include <FL/fl_draw.H> 00038 #include <FL/math.h> 00039 00040 // avoid problems with some platforms that don't 00041 // implement hypot. 00042 static double _fl_hypot(double x, double y) { 00043 return sqrt(x*x + y*y); 00044 } 00045 00046 void Fl_Graphics_Driver::arc(double x, double y, double r, double start, double end) { 00047 00048 // draw start point accurately: 00049 00050 double A = start*(M_PI/180); // Initial angle (radians) 00051 double X = r*cos(A); // Initial displacement, (X,Y) 00052 double Y = -r*sin(A); // from center to initial point 00053 fl_vertex(x+X,y+Y); // Insert initial point 00054 00055 // Maximum arc length to approximate with chord with error <= 0.125 00056 00057 double epsilon; { 00058 double r1 = _fl_hypot(fl_transform_dx(r,0), // Horizontal "radius" 00059 fl_transform_dy(r,0)); 00060 double r2 = _fl_hypot(fl_transform_dx(0,r), // Vertical "radius" 00061 fl_transform_dy(0,r)); 00062 00063 if (r1 > r2) r1 = r2; // r1 = minimum "radius" 00064 if (r1 < 2.) r1 = 2.; // radius for circa 9 chords/circle 00065 00066 epsilon = 2*acos(1.0 - 0.125/r1); // Maximum arc angle 00067 } 00068 A = end*(M_PI/180) - A; // Displacement angle (radians) 00069 int i = int(ceil(fabs(A)/epsilon)); // Segments in approximation 00070 00071 if (i) { 00072 epsilon = A/i; // Arc length for equal-size steps 00073 double cos_e = cos(epsilon); // Rotation coefficients 00074 double sin_e = sin(epsilon); 00075 do { 00076 double Xnew = cos_e*X + sin_e*Y; 00077 Y = -sin_e*X + cos_e*Y; 00078 fl_vertex(x + (X=Xnew), y + Y); 00079 } while (--i); 00080 } 00081 } 00082 00083 #if 0 // portable version. X-specific one in fl_vertex.cxx 00084 void fl_circle(double x,double y,double r) { 00085 _fl_arc(x, y, r, r, 0, 360); 00086 } 00087 #endif 00088 00089 // 00090 // End of "$Id: fl_arc.cxx 7903 2010-11-28 21:06:39Z matt $". 00091 //