Ejemplo n.º 1
0
/**
 * Classify a point with respect to an edge, i.e. left, right of edge etc.
 * @param pt :: A point as V2D
 * @param edge :: A test edge object
 * @returns The type of the point
 */
PointClassification classify(const V2D &pt, const PolygonEdge &edge) {
  V2D p2 = pt;
  const V2D &a = edge.direction();
  V2D b = p2 - edge.start();
  double sa = a.X() * b.Y() - b.X() * a.Y();
  if (sa > 0.0) {
    return OnLeft;
  }
  if (sa < 0.0) {
    return OnRight;
  }
  if ((a.X() * b.X() < 0.0) || (a.Y() * b.Y() < 0.0)) {
    return Behind;
  }
  if (a.norm() < b.norm()) {
    return Beyond;
  }
  if (edge.start() == p2) {
    return Origin;
  }
  if (edge.end() == p2) {
    return Destination;
  }
  return Between;
}
Ejemplo n.º 2
0
/**
 * Insert a new vertex.
 * @param pt A new point for the shape
 */
void ConvexPolygon::insert(const V2D &pt) {
  m_vertices.push_back(pt);
  // Update extrema
  m_minX = std::min(m_minX, pt.X());
  m_maxX = std::max(m_maxX, pt.X());
  m_minY = std::min(m_minY, pt.Y());
  m_maxY = std::max(m_maxY, pt.Y());
}
Ejemplo n.º 3
0
/**
 * Compute the area of a triangle given by 3 points (a,b,c) using the
 * convention in "Computational Geometry in C" by J. O'Rourke
 * @param a :: The first vertex in the set
 * @param b :: The second vertex in the set
 * @param c :: The third vertex in the set
 */
double ConvexPolygon::triangleArea(const V2D &a, const V2D &b,
                                   const V2D &c) const {
  return 0.5 * (b.X() - a.X()) * (c.Y() - a.Y()) -
         (c.X() - a.X()) * (b.Y() - a.Y());
}