Back to index

texmacs  1.0.7.15
curve.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : curve.hpp
00004 * DESCRIPTION: mathematical curves
00005 * COPYRIGHT  : (C) 2003  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef CURVE_H
00013 #define CURVE_H
00014 #include "point.hpp"
00015 
00016 class curve_rep: public abstract_struct {
00017 public:
00018   inline curve_rep () {}
00019   inline virtual ~curve_rep () {}
00020 
00021   inline virtual int nr_components () { return 1; }
00022   // the number of components of the curve is useful for getting
00023   // nice parameterizations when concatenating curves
00024 
00025   virtual point evaluate (double t) = 0;
00026   // gives a point on the curve for its intrinsic parameterization
00027   // curves are parameterized from 0.0 to 1.0
00028 
00029   array<point> rectify (double eps);
00030   // returns a rectification of the curve, which, modulo reparameterization
00031   // has a uniform distance of at most 'eps' to the original curve
00032 
00033   virtual void rectify_cumul (array<point>& a, double eps) = 0;
00034   // add rectification of the curve  (except for the starting point)
00035   // to an existing polysegment
00036 
00037   /*
00038   NOTE: more routines should be added later so that one
00039   can reliably compute the intersections between curves
00040   One might for instance take the following:
00041   */
00042   virtual double bound (double t, double eps) = 0;
00043   // return delta such that |t' - t| < delta => |c(t') - c(t)| < eps.
00044 
00045   virtual point grad (double t, bool& error) = 0;
00046   // compute the first derivative at t.
00047   // set error= true if this derivative does not exist.
00048 
00049   virtual double curvature (double t1, double t2) = 0;
00050   // compute a bound for the second derivative between t1 and t2.
00051   /* FIXME: What is computed is *really* a bound for the curvature,
00052        not for the norm of the second derivative. Make it precise
00053        what it is that is computed exactly. */
00054   // return a very large number if such a bound does not exist.
00055 
00056   // returns the number of control points which belong to the curve.
00057   // these control points are ordered and come first in pts & cips.
00058   virtual int get_control_points (
00059             array<double>&abs, array<point>& pts, array<path>& cip);
00060 
00061   virtual array<double> find_closest_points (
00062             double t1, double t2, point p, double eps);
00063 
00064   virtual double find_closest_point (
00065             double t1, double t2, point p, double eps, bool& found);
00066 };
00067 
00068 class curve {
00069   ABSTRACT_NULL(curve);
00070   inline point operator () (double t) { return rep->evaluate (t); }
00071   inline bool operator == (curve c) { return rep == c.rep; }
00072   inline bool operator != (curve c) { return rep != c.rep; }
00073 };
00074 ABSTRACT_NULL_CODE(curve);
00075 
00076 curve segment (point p1, point p2);
00077 curve poly_segment (array<point> a, array<path> cip);
00078 curve spline (
00079   array<point> a, array<path> cip, bool close=false, bool interpol=true);
00080 curve arc (array<point> a, array<path> cip, bool close=false);
00081 curve operator * (curve c1, curve c2);
00082 curve invert (curve c);
00083 
00084 array<point> intersection (curve f, curve g, point p0, double eps);
00085 point closest (curve f, point p);
00086 
00087 #endif // defined CURVE_H