|
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_curve.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Bezier curve 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 00038 #include <FL/fl_draw.H> 00039 #include <math.h> 00040 00041 void Fl_Graphics_Driver::curve(double X0, double Y0, 00042 double X1, double Y1, 00043 double X2, double Y2, 00044 double X3, double Y3) { 00045 00046 double x = fl_transform_x(X0,Y0); 00047 double y = fl_transform_y(X0,Y0); 00048 00049 // draw point 0: 00050 fl_transformed_vertex(x,y); 00051 00052 double x1 = fl_transform_x(X1,Y1); 00053 double yy1 = fl_transform_y(X1,Y1); 00054 double x2 = fl_transform_x(X2,Y2); 00055 double y2 = fl_transform_y(X2,Y2); 00056 double x3 = fl_transform_x(X3,Y3); 00057 double y3 = fl_transform_y(X3,Y3); 00058 00059 // find the area: 00060 double a = fabs((x-x2)*(y3-yy1)-(y-y2)*(x3-x1)); 00061 double b = fabs((x-x3)*(y2-yy1)-(y-y3)*(x2-x1)); 00062 if (b > a) a = b; 00063 00064 // use that to guess at the number of segments: 00065 int n = int(sqrt(a)/4); 00066 if (n > 1) { 00067 if (n > 100) n = 100; // make huge curves not hang forever 00068 00069 double e = 1.0/n; 00070 00071 // calculate the coefficients of 3rd order equation: 00072 double xa = (x3-3*x2+3*x1-x); 00073 double xb = 3*(x2-2*x1+x); 00074 double xc = 3*(x1-x); 00075 // calculate the forward differences: 00076 double dx1 = ((xa*e+xb)*e+xc)*e; 00077 double dx3 = 6*xa*e*e*e; 00078 double dx2 = dx3 + 2*xb*e*e; 00079 00080 // calculate the coefficients of 3rd order equation: 00081 double ya = (y3-3*y2+3*yy1-y); 00082 double yb = 3*(y2-2*yy1+y); 00083 double yc = 3*(yy1-y); 00084 // calculate the forward differences: 00085 double dy1 = ((ya*e+yb)*e+yc)*e; 00086 double dy3 = 6*ya*e*e*e; 00087 double dy2 = dy3 + 2*yb*e*e; 00088 00089 // draw points 1 .. n-2: 00090 for (int m=2; m<n; m++) { 00091 x += dx1; 00092 dx1 += dx2; 00093 dx2 += dx3; 00094 y += dy1; 00095 dy1 += dy2; 00096 dy2 += dy3; 00097 fl_transformed_vertex(x,y); 00098 } 00099 00100 // draw point n-1: 00101 fl_transformed_vertex(x+dx1, y+dy1); 00102 } 00103 00104 // draw point n: 00105 fl_transformed_vertex(x3,y3); 00106 } 00107 00108 // 00109 // End of "$Id: fl_curve.cxx 7903 2010-11-28 21:06:39Z matt $". 00110 //