Back to index

texmacs  1.0.7.15
Classes | Typedefs | Functions | Variables
curve.cpp File Reference
#include "path.hpp"
#include "curve.hpp"
#include "frame.hpp"
#include "equations.hpp"
#include "math_util.hpp"
#include "polynomial.hpp"
#include "merge_sort.hpp"

Go to the source code of this file.

Classes

struct  curvet
struct  less_eq_curvet
struct  segment_rep
struct  poly_segment_rep
struct  spline_rep
struct  arc_rep
struct  compound_curve_rep
struct  inverted_curve_rep
struct  transformed_curve_rep

Typedefs

typedef polynomial< double > dpol
typedef vector< polynomial
< double > > 
dpols

Functions

static array< curvetcurvet_closest_points (curve c, double t1, double t2, point p, double eps)
point closest (curve f, point p)
point grad (curve f, double t)
bool intersection (curve f, curve g, double &t, double &u)
array< pointintersection (curve f, curve g, point p0, double eps)
curve segment (point p1, point p2)
curve poly_segment (array< point > a, array< path > cip)
static double prod (double x, int n)
curve spline (array< point > a, array< path > cip, bool close, bool interpol)
curve arc (array< point > a, array< path > cip, bool close)
curve operator* (curve c1, curve c2)
curve invert (curve c)

Variables

static const double epsilon = 0.01

Class Documentation

struct curvet

Definition at line 63 of file curve.cpp.

Class Members
double dist
double t

Typedef Documentation

typedef polynomial<double> dpol

Definition at line 337 of file curve.cpp.

typedef vector<polynomial<double> > dpols

Definition at line 338 of file curve.cpp.


Function Documentation

curve arc ( array< point a,
array< path cip,
bool  close 
)

Definition at line 788 of file curve.cpp.

                                                  {
  return tm_new<arc_rep> (a, cip, close);
}

Here is the caller graph for this function:

point closest ( curve  f,
point  p 
)

Definition at line 150 of file curve.cpp.

                           {
  array<double> abs;
  array<point> pts;
  array<path> rcip;
  f->get_control_points (abs, pts, rcip);
  if (N(abs) == 0) return f(0);
  double t1= abs[0];
  double t2= abs[N(abs)-1];
  double best= 0;
  double eps = norm (f(0) - p);
  for (int i=0; i<10; i++) {
    bool found= false;
    double t= f->find_closest_point (t1, t2, p, eps, found);
    if (found) best= t;
    else break;
    double eps2= norm (f(t) - p);
    if (eps2 >= 0.9 * eps) break;
    eps= eps2;
  }
  return f(best);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static array<curvet> curvet_closest_points ( curve  c,
double  t1,
double  t2,
point  p,
double  eps 
) [static]

Definition at line 73 of file curve.cpp.

{
  array<curvet> res;
  if (t1>t2) {
    array<curvet> r1, r2;
    r1= curvet_closest_points (c, 0.0, t2, p, eps);
    r2= curvet_closest_points (c, t1, 1.0, p, eps);
    res= r1 << r2;
  }
  else {
    double t;
    double closest= -1;
    point pclosest;
    double n0= tm_infinity;
    bool stored= true;
    double nprec= n0;
    bool decreasing= false;
    for (t=t1; t<=t2;) {
      point pt= c->evaluate(t);
      double n= norm (pt - p);
      if (n < n0) {
       n0= n;
       closest= t;
       pclosest= pt;
       stored= false;
      }
      decreasing= n<nprec;
      if (!stored && !decreasing) {
        curvet ct;
        ct.dist= norm (pclosest - p);
        ct.t= closest;
       res << ct;
       stored= true;
      }
      if (stored && decreasing)
        n0= tm_infinity;
      double delta= (n - eps) / 2;
      t += max (0.00001, c->bound (t, max (eps, delta)));
      nprec= n;
    }
    if (!stored && decreasing) {
      curvet ct;
      ct.dist= norm (pclosest - p);
      ct.t= closest;
      res << ct;
    }
  }
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point grad ( curve  f,
double  t 
)

Definition at line 173 of file curve.cpp.

                         {
  bool error= false;
  return f->grad (t, error);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool intersection ( curve  f,
curve  g,
double &  t,
double &  u 
)

Definition at line 179 of file curve.cpp.

                                                      {
  // for two dimensional curves only
  double d= norm (f (t) - g (u));
  while (!fnull (d, 1.0e-9)) {
    point  ft = f (t);
    point  gu = g (u);
    point  gf = grad (f, t);
    point  gg = grad (g, u);
    double det= gf[0] * gg[1] - gf[1] * gg[0];
    if (fnull (det, 1.0e-12)) break;
    double dt = ((gu[0] - ft[0]) * gg[1] - (gu[1] - ft[1]) * gg[0]) / det;
    double du = ((gu[0] - ft[0]) * gf[1] - (gu[1] - ft[1]) * gf[0]) / det;
    double T  = t + dt;
    double U  = u + du;
    if (T < 0.0 || T > 1.0 || U < 0.0 || U > 1.0) break;
    double D  = norm (f (T) - g (U));
    if (D > 0.9 * d) break;
    t= T; u= U; d= D;
  }
  return fnull (d, 1.0e-9);
}

Here is the call graph for this function:

array<point> intersection ( curve  f,
curve  g,
point  p0,
double  eps 
)

Definition at line 202 of file curve.cpp.

                                                      {
  // For local intersections only
  array<point> res;
  if (is_nil (f) || is_nil (g)) return res;
  bool found= false;
  double d1, d2;
  if (f==g) {
    array<double> pts= f->find_closest_points (0.0, 1.0, p0, eps);
    if (N(pts)>=2) {
      d1= pts[0];
      d2= pts[1];
      found= intersection (f, f, d1, d2);
    }
  }
  else {
    bool res1, res2;
    d1= f->find_closest_point (0.0, 1.0, p0, eps, res1);
    d2= g->find_closest_point (0.0, 1.0, p0, eps, res2);
    if (res1 && res2)
      found= intersection (f, g, d1, d2);
  }
  if (found)
    res << f (d1);
  return res;
}

Here is the call graph for this function:

curve invert ( curve  c)

Definition at line 883 of file curve.cpp.

                 {
  return tm_new<inverted_curve_rep> (c);
}
curve operator* ( curve  c1,
curve  c2 
)

Definition at line 837 of file curve.cpp.

                                {
  // FIXME: we might want to test whether c1(1.0) is approx equal to c2(0.0)
  return tm_new<compound_curve_rep> (c1, c2);
}
curve poly_segment ( array< point a,
array< path cip 
)

Definition at line 328 of file curve.cpp.

                                               {
  return tm_new<poly_segment_rep> (a, cip);
}

Here is the caller graph for this function:

static double prod ( double  x,
int  n 
) [static]

Definition at line 528 of file curve.cpp.

                       {
  double r;
  if (n<=0) return 1;
  r=x; n--;
  while (n--)
    r*=(x-n);
  return r;
}

Here is the caller graph for this function:

curve segment ( point  p1,
point  p2 
)

Definition at line 273 of file curve.cpp.

                             {
  return tm_new<segment_rep> (p1, p2);
}

Here is the caller graph for this function:

curve spline ( array< point a,
array< path cip,
bool  close,
bool  interpol 
)

Definition at line 670 of file curve.cpp.

                                                                    {
  return tm_new<spline_rep> (a, cip, close, interpol);
}

Here is the caller graph for this function:


Variable Documentation

const double epsilon = 0.01 [static]

Definition at line 336 of file curve.cpp.