Back to index

texmacs  1.0.7.15
Functions
poly_line.cpp File Reference
#include "poly_line.hpp"

Go to the source code of this file.

Functions

double square (double x)
double min (point p)
double max (point p)
double l2_norm (point p)
double inner (point p, point q)
double distance (point p, point q)
point project (point p, point q1, point q2)
double distance (point p, point q1, point q2)
point inf (point p, point q)
point sup (point p, point q)
point abs (point p)
bool nearby (point p, poly_line pl)
point inf (poly_line pl)
point sup (poly_line pl)
poly_line operator+ (poly_line pl, point p)
poly_line operator- (poly_line pl, point p)
poly_line operator* (double x, poly_line pl)
poly_line normalize (poly_line pl)
double length (poly_line pl)
point access (poly_line pl, double t)
array< double > vertices (poly_line pl)
void invariants (poly_line pl, int level, array< tree > &disc, array< double > &cont)

Function Documentation

point abs ( point  p)

Definition at line 104 of file poly_line.cpp.

              {
  point r (N(p));
  for (int i=0; i<N(p); i++)
    r[i]= (p[i] > 0? p[i]: -p[i]);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point access ( poly_line  pl,
double  t 
)

Definition at line 193 of file poly_line.cpp.

                                {
  if (t < 0) return pl[0];
  for (int i=1; i<N(pl); i++) {
    point dp= pl[i] - pl[i-1];
    double len= l2_norm (dp);
    if (t < len) return pl[i-1] + (t / len) * dp;
    t -= len;
  }
  return pl[N(pl)-1];
}

Here is the call graph for this function:

Here is the caller graph for this function:

double distance ( point  p,
point  q 
)

Definition at line 56 of file poly_line.cpp.

                            {
  ASSERT (N(p) == N(q), "unequal lengths");
  double s= 0.0;
  for (int i=0; i<N(p); i++)
    s += square (q[i] - p[i]);
  return sqrt (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double distance ( point  p,
point  q1,
point  q2 
)

Definition at line 80 of file poly_line.cpp.

                                       {
  if (q1 == q2) return distance (p, q1);
  else return distance (p, project (p, q1, q2));
}

Here is the call graph for this function:

point inf ( point  p,
point  q 
)

Definition at line 86 of file poly_line.cpp.

                       {
  ASSERT (N(p) == N(q), "unequal lengths");
  point r (N(p));
  for (int i=0; i<N(p); i++)
    r[i]= min (p[i], q[i]);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point inf ( poly_line  pl)

Definition at line 130 of file poly_line.cpp.

                   {
  ASSERT (N(pl) > 0, "non zero length expected");
  point p= pl[0];
  for (int i=1; i<N(pl); i++)
    p= inf (p, pl[i]);
  return p;
}

Here is the call graph for this function:

double inner ( point  p,
point  q 
)

Definition at line 47 of file poly_line.cpp.

                         {
  ASSERT (N(p) == N(q), "unequal lengths");
  double s= 0.0;
  for (int i=0; i<N(p); i++)
    s += p[i] * q[i];
  return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void invariants ( poly_line  pl,
int  level,
array< tree > &  disc,
array< double > &  cont 
)

Definition at line 319 of file poly_line.cpp.

{
  double l= length (pl);
  int pieces= 20;
  for (int i=0; i<=pieces; i++) {
    double t= (0.999999999 * i) / pieces;
    point  p= access (pl, t * l);
    cont << p;
  }

  if (level <= 1) {
    array<double> ts= vertices (pl);
    disc << tree (as_string (N(ts)));
    cont << (2.5 * ts);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

double l2_norm ( point  p)

Definition at line 39 of file poly_line.cpp.

                  {
  double s= 0.0;
  for (int i=0; i<N(p); i++)
    s += square (p[i]);
  return sqrt (s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double length ( poly_line  pl)

Definition at line 185 of file poly_line.cpp.

                      {
  double len= 0.0;
  for (int i=1; i<N(pl); i++)
    len += distance (pl[i], pl[i-1]);
  return len;
}

Here is the call graph for this function:

double max ( point  p)

Definition at line 30 of file poly_line.cpp.

              {
  ASSERT (N(p) > 0, "non zero length expected");
  double r= p[0];
  for (int i=1; i<N(p); i++)
    r= max (r, p[i]);
  return r;
}

Here is the call graph for this function:

double min ( point  p)

Definition at line 21 of file poly_line.cpp.

              {
  ASSERT (N(p) > 0, "non zero length expected");
  double r= p[0];
  for (int i=1; i<N(p); i++)
    r= min (r, p[i]);
  return r;
}

Here is the call graph for this function:

bool nearby ( point  p,
poly_line  pl 
)

Definition at line 125 of file poly_line.cpp.

                               {
  return distance (p, pl) <= 5.0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 175 of file poly_line.cpp.

                         {
  if (N(pl) == 0) return pl;
  pl= pl - inf (pl);
  if (N(pl) == 1) return pl;
  double sc= max (sup (pl));
  if (sc == 0.0) return pl;
  return (1.0 / sc) * pl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

poly_line operator* ( double  x,
poly_line  pl 
)

Definition at line 166 of file poly_line.cpp.

                                    {
  int i, n= N(pl);
  poly_line r (n);
  for (i=0; i<n; i++)
    r[i]= x * pl[i];
  return r;
}

Here is the call graph for this function:

poly_line operator+ ( poly_line  pl,
point  p 
)

Definition at line 148 of file poly_line.cpp.

                                   {
  int i, n= N(pl);
  poly_line r (n);
  for (i=0; i<n; i++)
    r[i]= pl[i] + p;
  return r;
}

Here is the call graph for this function:

poly_line operator- ( poly_line  pl,
point  p 
)

Definition at line 157 of file poly_line.cpp.

                                   {
  int i, n= N(pl);
  poly_line r (n);
  for (i=0; i<n; i++)
    r[i]= pl[i] - p;
  return r;
}

Here is the call graph for this function:

point project ( point  p,
point  q1,
point  q2 
)

Definition at line 65 of file poly_line.cpp.

                                      {
  ASSERT (N(p) == N(q1) && N(p) == N(q2), "unequal lengths");
  int i, n= N(p);
  double s= 0.0, t= 0.0;
  for (i=0; i<n; i++) {
    s += (q2[i] - q1[i]) * (p[i] - q1[i]);
    t += square (q2[i] - q1[i]);
  }
  double a= s / t;
  if (a < 0.0) return q1;
  if (a > 1.0) return q2;
  return q1 + a * (q2 - q1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double square ( double  x) [inline]

Definition at line 14 of file poly_line.cpp.

{ return x*x; }

Here is the caller graph for this function:

point sup ( point  p,
point  q 
)

Definition at line 95 of file poly_line.cpp.

                       {
  ASSERT (N(p) == N(q), "unequal lengths");
  point r (N(p));
  for (int i=0; i<N(p); i++)
    r[i]= max (p[i], q[i]);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point sup ( poly_line  pl)

Definition at line 139 of file poly_line.cpp.

                   {
  ASSERT (N(pl) > 0, "non zero length expected");
  point p= pl[0];
  for (int i=1; i<N(pl); i++)
    p= sup (p, pl[i]);
  return p;
}

Here is the call graph for this function:

array<double> vertices ( poly_line  pl)

Definition at line 281 of file poly_line.cpp.

                        {
  pl= (1.0 / length (pl)) * pl;
  array<double> r;
  double t = 0.0;
  double dt= 0.025;
  r << 0.0;
  int    todo_i= -1;
  double todo_t= 0.0;
  double todo_p= 0.0;
  for (int i=0; i+1<N(pl); i++) {
    if (t >= r[N(r)-1] + dt && t <= 1.0 - dt) {
      double t1= max (t - dt, 0.000000001);
      double t2= min (t + dt, 0.999999999);
      point  p = pl[i];
      point  p1= access (pl, t1);
      point  p2= access (pl, t2);
      double pr= inner (p1 - p, p2 - p);
      if (pr >= 0 && (todo_i < 0 || pr > todo_p)) {
        todo_i= i;
        todo_t= t;
        todo_p= pr;
      }
    }
    t += distance (pl[i+1], pl[i]);
    if (todo_i >= 0 && t >= todo_t + dt) {
      r << todo_t;
      todo_i= -1;
    }
  }
  r << 1.0;
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function: