Back to index

texmacs  1.0.7.15
Functions
point.cpp File Reference
#include "point.hpp"
#include "math_util.hpp"

Go to the source code of this file.

Functions

point operator- (point p)
point operator+ (point p1, point p2)
point operator- (point p1, point p2)
point operator* (double x, point p)
point operator/ (point p, double x)
bool operator== (point p1, point p2)
bool is_point (tree t)
point as_point (tree t)
tree as_tree (point p)
double operator* (point p1, point p2)
static point mult (double re, double im, point p)
point rotate_2D (point p, point o, double angle)
double norm (point p)
double arg (point p)
point proj (axis ax, point p)
double dist (axis ax, point p)
double seg_dist (axis ax, point p)
bool collinear (point p1, point p2)
bool linearly_dependent (point p1, point p2, point p3)
bool orthogonalize (point &i, point &j, point p1, point p2, point p3)
axis midperp (point p1, point p2, point p3)
point intersection (axis A, axis B)
bool inside_rectangle (point p, point p1, point p2)

Function Documentation

double arg ( point  p)

Definition at line 123 of file point.cpp.

              {
  double n= norm(p);
  p=p/n;
  if (p[1]<0) return 2*tm_PI-acos(p[0]);
  else return acos(p[0]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 75 of file point.cpp.

                  {
  if (!is_tuple (t) && !is_point (t)) return point ();
  else {
    int i, n= N(t);
    point p(n);
    for (i=0; i<n; i++)
      p[i]= as_double (t[i]);
    return p;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree as_tree ( point  p)

Definition at line 87 of file point.cpp.

                  {
  int i, n= N(p);
  tree t (_POINT, n);
  for (i=0; i<n; i++)
    t[i]= as_string (p[i]);
  return t;
}

Here is the call graph for this function:

bool collinear ( point  p1,
point  p2 
)

Definition at line 162 of file point.cpp.

                               {
  return fnull (fabs (p1*p2) - norm(p1)*norm(p2), 1.0e-6);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double dist ( axis  ax,
point  p 
)

Definition at line 145 of file point.cpp.

                        {
  return norm (p - proj (ax, p));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool inside_rectangle ( point  p,
point  p1,
point  p2 
)

Definition at line 227 of file point.cpp.

                                               {
  return p[0]>=p1[0] && p[1]>=p1[1]
      && p[0]<=p2[0] && p[1]<=p2[1];
}

Here is the caller graph for this function:

point intersection ( axis  A,
axis  B 
)

Definition at line 197 of file point.cpp.

                              {
  point i, j;
  if (!orthogonalize (i, j, A.p0, A.p1, B.p0)) {
    if (orthogonalize (i, j, A.p0, A.p1, B.p1))
      return B.p0;
    else
      return point (0);
  }
  point a(2), b(2), u(2), v(2), p(2);
  a[0]= a[1]= 0;
  u[0]= (A.p1 - A.p0) * i;
  u[1]= (A.p1 - A.p0) * j;
  b[0]= (B.p0 - A.p0) * i;
  b[1]= (B.p0 - A.p0) * j;
  v[0]= (B.p1 - B.p0) * i;
  v[1]= (B.p1 - B.p0) * j;
  if (fnull (norm (u), 1e-6) ||
      fnull (norm (v), 1e-6) ||
      collinear (u, v))
    return point (0);
  else {
    double t;
    t= (v[0] * (b[1]-a[1]) + v[1] * (a[0]-b[0]))
       /
       (v[0]*u[1] - v[1]*u[0]);
    return A.p0 + t * (u[0]*i + u[1]*j);
  }
}

Here is the call graph for this function:

bool is_point ( tree  t)

Definition at line 70 of file point.cpp.

                  {
  return L(t)==_POINT;
}

Here is the caller graph for this function:

bool linearly_dependent ( point  p1,
point  p2,
point  p3 
)

Definition at line 167 of file point.cpp.

                                                  {
  return fnull (norm (p1-p2), 1e-6) ||
        fnull (norm (p2-p3), 1e-6) ||
        fnull (norm (p3-p1), 1e-6) ||
        collinear (p2-p1, p3-p1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

axis midperp ( point  p1,
point  p2,
point  p3 
)

Definition at line 183 of file point.cpp.

                                       {
  axis a;
  if (linearly_dependent (p1, p2, p3))
    a.p0= a.p1= point (0);
  else {
    point i, j;
    orthogonalize (i, j, p1, p2, p3);
    a.p0= (p1+p2) / 2;
    a.p1= a.p0 + j;
  }
  return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static point mult ( double  re,
double  im,
point  p 
) [static]

Definition at line 105 of file point.cpp.

                                     {
  if (N(p)==0) p= point (0.0, 0.0);
  if (N(p)==1) p= point (p[0], 0.0);
  return point (re * p[0] - im * p[1],
              re * p[1] + im * p[0]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double norm ( point  p)

Definition at line 118 of file point.cpp.

               {
  return sqrt (p*p);
}

Here is the call graph for this function:

point operator* ( double  x,
point  p 
)

Definition at line 43 of file point.cpp.

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

Here is the call graph for this function:

double operator* ( point  p1,
point  p2 
)

Definition at line 96 of file point.cpp.

                                {
  int i, n= min (N(p1), N(p2));
  double r= 0;
  for (i=0; i<n; i++)
    r+= p1[i] * p2[i];
  return r;
}

Here is the call graph for this function:

point operator+ ( point  p1,
point  p2 
)

Definition at line 25 of file point.cpp.

                                {
  int i, n= min (N(p1), N(p2));
  point r (n);
  for (i=0; i<n; i++)
    r[i]= p1[i] + p2[i];
  return r;
}

Here is the call graph for this function:

point operator- ( point  p)

Definition at line 16 of file point.cpp.

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

Here is the call graph for this function:

point operator- ( point  p1,
point  p2 
)

Definition at line 34 of file point.cpp.

                                {
  int i, n= min (N(p1), N(p2));
  point r (n);
  for (i=0; i<n; i++)
    r[i]= p1[i] - p2[i];
  return r;
}

Here is the call graph for this function:

point operator/ ( point  p,
double  x 
)

Definition at line 52 of file point.cpp.

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

Here is the call graph for this function:

bool operator== ( point  p1,
point  p2 
)

Definition at line 61 of file point.cpp.

                                 {
  if (N(p1) != N(p2)) return false;
  int i, n= N(p1);
  for (i=0; i<n; i++)
    if (!fnull (p1[i]-p2[i], 1e-6)) return false;
  return true;
}

Here is the call graph for this function:

bool orthogonalize ( point i,
point j,
point  p1,
point  p2,
point  p3 
)

Definition at line 174 of file point.cpp.

                                                                      {
  if (linearly_dependent (p1, p2, p3)) return false;
  i= (p2-p1) / norm (p2-p1);
  j= (p3-p1) - ((p3-p1) * i) * i;
  j= j / norm (j);
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point proj ( axis  ax,
point  p 
)

Definition at line 131 of file point.cpp.

                        {
  int i, n= min (N(ax.p0), N(ax.p1));
  point a (n), b (n);
  for (i=0; i<n ; i++) {
    a[i]= ax.p1[i] - ax.p0[i];
    b[i]= ax.p0[i];
  }
  if (norm (a) < 1.0e-6)
    return ax.p0;
  else
    return b + ((a*p - a*b) / (a*a)) * a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

point rotate_2D ( point  p,
point  o,
double  angle 
)

Definition at line 113 of file point.cpp.

                                           {
  return mult (cos (angle), sin (angle), p - o) + o;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double seg_dist ( axis  ax,
point  p 
)

Definition at line 150 of file point.cpp.

                            {
  point ab= ax.p1 - ax.p0;
  point ba= ax.p0 - ax.p1;
  point ap= p - ax.p0;
  point bp= p - ax.p1;
  if (ab * ap > 0 && ba * bp > 0)
    return dist (ax, p);
  else
    return min (norm (ap), norm (bp));
}

Here is the call graph for this function:

Here is the caller graph for this function: