Exemplo n.º 1
0
 Face_index_observer (Arrangement_2& arr) :
   CGAL::Arr_observer<Arrangement_2> (arr),
   n_faces (0)
 {
   CGAL_precondition (arr.is_empty());
   
   arr.unbounded_face()->set_data (0);
   n_faces++;
 }
Exemplo n.º 2
0
 Point_3 operator()(const Vertex& v) const {
     CGAL_precondition((CGAL::circulator_size(v.vertex_begin()) & 1) == 0);
     std::size_t degree = CGAL::circulator_size(v.vertex_begin()) / 2;
     double alpha = (4.0 - 2.0 * std::cos(2.0 * CGAL_PI / degree)) / 9.0;
     Vector_3 vec = (v.point() - CGAL::ORIGIN) * (1.0 - alpha);
     HV_circulator h = v.vertex_begin();
     do {
         vec = vec + (h->opposite()->vertex()->point() - CGAL::ORIGIN)
                 * alpha / static_cast<double> (degree);
         ++h;
         CGAL_assertion(h != v.vertex_begin()); // even degree guaranteed
         ++h;
     } while (h != v.vertex_begin());
     return (CGAL::ORIGIN + vec);
 }
Exemplo n.º 3
0
// Moves to the closest target (appending the motion).
// Returns whether a motion was successfully found.
// Updates source to the target selected.
// Removes said target from targets.
bool BufferingPlayer::move_to_closest_target(Reference_point& source, Reference_point_vec& targets, Motion& motion) {
	TIMED_TRACE_ENTER("move_to_closest_target");
	CGAL_precondition(!env->get_target_configurations().empty());
	Ref_p_vec::iterator target_reached;
	int target_index;

	// Plan a motion to the closest remaining target
	bool path_found = planner.query_closest_point(
		source, 
		targets,
		target_index,
		// Append it to the output motion
		motion);
	ASSERT_CONDITION(path_found, "targets are connected but could not find path!");

	// Reached another target
	target_reached = targets.begin() + target_index;
	source = *target_reached;
	targets.erase(target_reached);

	TIMED_TRACE_EXIT("move_to_closest_target");
	return true;
}
Exemplo n.º 4
0
static void
FindPolynomialRoots(
		    const FLOAT     *a,                               /* Coefficients */
		    FLOAT           *u,                               /* Real component of each root */
		    FLOAT           *v,                               /* Imaginary component of each root */
		    FLOAT           *conv,                            /* Convergence constant associated with each root */
		    register long   n,                                /* Degree of polynomial (order-1) */
		    long            maxiter,                          /* Maximum number of iterations */
		    long            fig                               /* The number of decimal figures to be computed */
		    )
{
  int number_of_ITERATE=0;
  int number_of_INIT=0;
  CGAL_precondition(static_cast<unsigned int>(fig) < MAXN);
  int i;
  register int j;
  FLOAT h[MAXN + 3], b[MAXN + 3], c[MAXN + 3], d[MAXN + 3], e[MAXN + 3];
  /* [-2 : n] */
  FLOAT K, ps, qs, pt, qt, s, rev, r= std::numeric_limits<double>::infinity();
  int t;
  FLOAT p=std::numeric_limits<double>::infinity(), q=std::numeric_limits<double>::infinity();

  /* Zero elements with negative indices */
  b[2 + -1] = b[2 + -2] =
    c[2 + -1] = c[2 + -2] =
    d[2 + -1] = d[2 + -2] =
    e[2 + -1] = e[2 + -2] =
    h[2 + -1] = h[2 + -2] = 0.0;

  /* Copy polynomial coefficients to working storage */
  for (j = n; j >= 0; j--)
    h[2 + j] = *a++;                          /* Note reversal of coefficients */

  t = 1;
  K = std::pow(10.0, (double)(fig));            /* Relative accuracy */

  for (; h[2 + n] == 0.0; n--) {                /* Look for zero high-order coeff. */
    *u++ = 0.0;
    *v++ = 0.0;
    *conv++ = K;
  }

 INIT:
  ++number_of_INIT;
  if (number_of_INIT > 1000) {
    std::cerr << "Too many INITs" << std::flush;
    return;
  }

  if (n == 0)
    return;

  ps = qs = pt = qt = s = 0.0;
  rev = 1.0;
  K = std::pow(10.0, (double)(fig));

  if (n == 1) {
    r = -h[2 + 1] / h[2 + 0];
    goto LINEAR;
  }

  for (j = n; j >= 0; j--)                      /* Find geometric mean of coeff's */
    if (h[2 + j] != 0.0)
      s += std::log(std::fabs(h[2 + j]));
  s = std::exp(s / (n + 1));

  for (j = n; j >= 0; j--)                      /* Normalize coeff's by mean */
    h[2 + j] /= s;

  if (std::fabs(h[2 + 1] / h[2 + 0]) < std::fabs(h[2 + n - 1] / h[2 + n])) {
  REVERSE:
    t = -t;
    for (j = (n - 1) / 2; j >= 0; j--) {
      s = h[2 + j];
      h[2 + j] = h[2 + n - j];
      h[2 + n - j] = s;
    }
  }
  if (qs != 0.0) {
    p = ps;
    q = qs;
  }
  else {
    if (h[2 + n - 2] == 0.0) {
      q = 1.0;
      p = -2.0;
    }
    else {
      q = h[2 + n] / h[2 + n - 2];
      p = (h[2 + n - 1] - q * h[2 + n - 3]) / h[2 + n - 2];
    }
    if (n == 2)
      goto QADRTIC;
    r = 0.0;
  }
 ITERATE:
  ++number_of_ITERATE;
  if (number_of_ITERATE > 1000) {
    std::cerr << "Too many ITERATEs" << std::flush;
    return;
  }
  for (i = maxiter; i > 0; i--) {

    for (j = 0; j <= n; j++) {                /* BAIRSTOW */
      b[2 + j] = h[2 + j] - p * b[2 + j - 1] - q * b[2 + j - 2];
      c[2 + j] = b[2 + j] - p * c[2 + j - 1] - q * c[2 + j - 2];
    }
    if ((h[2 + n - 1] != 0.0) && (b[2 + n - 1] != 0.0)) {
      if (std::fabs(h[2 + n - 1] / b[2 + n - 1]) >= K) {
	b[2 + n] = h[2 + n] - q * b[2 + n - 2];
      }
      if (b[2 + n] == 0.0)
	goto QADRTIC;
      if (K < std::fabs(h[2 + n] / b[2 + n]))
	goto QADRTIC;
    }

    for (j = 0; j <= n; j++) {                /* NEWTON */
      /* Calculate polynomial at r */
      d[2 + j] = h[2 + j] + r * d[2 + j - 1];
      /* Calculate derivative at r */
      e[2 + j] = d[2 + j] + r * e[2 + j - 1];
    }
    if (d[2 + n] == 0.0)
      goto LINEAR;
    if (K < std::fabs(h[2 + n] / d[2 + n]))
      goto LINEAR;

    c[2 + n - 1] = -p * c[2 + n - 2] - q * c[2 + n - 3];
    s = c[2 + n - 2] * c[2 + n - 2] - c[2 + n - 1] * c[2 + n - 3];
    if (s == 0.0) {
      p -= 2.0;
      q *= (q + 1.0);
    }
    else {
      p += (b[2 + n - 1] * c[2 + n - 2] - b[2 + n] * c[2 + n - 3]) / s;
      q += (-b[2 + n - 1] * c[2 + n - 1] + b[2 + n] * c[2 + n - 2]) / s;
    }
    if (e[2 + n - 1] == 0.0)
      r -= 1.0;                             /* Minimum step */
    else
      r -= d[2 + n] / e[2 + n - 1];         /* Newton's iteration */
  }
  ps = pt;
  qs = qt;
  pt = p;
  qt = q;
  if (rev < 0.0)
    K /= 10.0;
  rev = -rev;
  goto REVERSE;

 LINEAR:
  if (t < 0)
    r = 1.0 / r;
  n--;
  *u++ = r;
  *v++ = 0.0;
  *conv++ = K;

  for (j = n; j >= 0; j--) {                    /* Polynomial deflation by lin-nomial */
    if ((d[2 + j] != 0.0) && (std::fabs(h[2 + j] / d[2 + j]) < K))
      h[2 + j] = d[2 + j];
    else
      h[2 + j] = 0.0;
  }

  if (n == 0)
    return;
  goto ITERATE;

 QADRTIC:
  if (t < 0) {
    p /= q;
    q = 1.0 / q;
  }
  n -= 2;

  if (0.0 < (q - (p * p / 4.0))) {              /* Two complex roots */
    *(u + 1) = *u = -p / 2.0;
    u += 2;
    s = sqrt(q - (p * p / 4.0));
    *v++ = s;
    *v++ = -s;
  }                                             /* Two real roots */
  else {
    s = std::sqrt(((p * p / 4.0)) - q);
    if (p < 0.0)
      *u++ = -p / 2.0 + s;
    else
      *u++ = -p / 2.0 - s;
    *u = q / u[-1];
    ++u;                                      // moved from lhs of before
    *v++ = 0.0;
    *v++ = 0.0;
  }
  *conv++ = K;
  *conv++ = K;

  for (j = n; j >= 0; j--) {                    /* Polynomial deflation by quadratic */
    if ((b[2 + j] != 0.0) && (std::fabs(h[2 + j] / b[2 + j]) < K))
      h[2 + j] = b[2 + j];
    else
      h[2 + j] = 0.0;
  }
  goto INIT;
}