示例#1
0
// Return true if the segment is a polygon diagonal
bool glc::isDiagonal(const QList<GLC_Point2d>& polygon, const int i0, const int i1)
{
	const int size= polygon.size();
	int iM= (i0 - 1) % size;
	if (iM < 0) iM= size - 1;
	int iP= (i0 + 1) % size;

	if (!segmentInCone(polygon[i0], polygon[i1], polygon[iM], polygon[iP]))
	{
		return false;
	}

	int j0= 0;
	int j1= size - 1;
	// test segment <polygon[i0], polygon[i1]> to see if it is a diagonal
	while (j0 < size)
	{
		if (j0 != i0 && j0 != i1 && j1 != i0 && j1 != i1)
		{
			if (isIntersected(polygon[i0], polygon[i1], polygon[j0], polygon[j1]))
				return false;
		}

		j1= j0;
		++j0;
	}

	return true;
}
示例#2
0
void GameProcess::placeEat() {
	bool isPlace = false;
	while (!isPlace) {
		int x = rand() % N;
		int y = rand() % M;
		if (!isIntersected(x, y)) {
			eat.x = x;
			eat.y = y;
			isPlace = true;
		}
	}

}
示例#3
0
template <typename PointNT> void
pcl::GridProjection<PointNT>::createSurfaceForCell (const Eigen::Vector3i &index,
                                                    std::vector <int> &pt_union_indices)
{
  // 8 vertices of the cell
  std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > vertices (8);

  // 4 end points that shared by 3 edges connecting the upper left front points
  Eigen::Vector4f pts[4];
  Eigen::Vector3f vector_at_pts[4];

  // Given the index of cell, caluate the coordinates of the eight vertices of the cell
  // index the index of the cell in (x,y,z) 3d format
  Eigen::Vector4f cell_center = Eigen::Vector4f::Zero ();
  getCellCenterFromIndex (index, cell_center);
  getVertexFromCellCenter (cell_center, vertices);

  // Get the indices of the cells which stores the 4 end points.
  Eigen::Vector3i indices[4];
  indices[0] = Eigen::Vector3i (index[0], index[1], index[2] - 1);
  indices[1] = Eigen::Vector3i (index[0], index[1], index[2]);
  indices[2] = Eigen::Vector3i (index[0], index[1] - 1, index[2]);
  indices[3] = Eigen::Vector3i (index[0] + 1, index[1], index[2]);

  // Get the coordinate of the 4 end points, and the corresponding vectors
  for (size_t i = 0; i < 4; ++i)
  {
    pts[i] = vertices[I_SHIFT_PT[i]];
    unsigned int index_1d = getIndexIn1D (indices[i]);
    if (cell_hash_map_.find (index_1d) == cell_hash_map_.end () ||
        occupied_cell_list_[index_1d] == 0)
      return;
    else
      vector_at_pts[i] = cell_hash_map_.at (index_1d).vect_at_grid_pt;
  }

  // Go through the 3 edges, test whether they are intersected by the surface
  for (size_t i = 0; i < 3; ++i)
  {
    std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > end_pts (2);
    std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > vect_at_end_pts (2);
    for (size_t j = 0; j < 2; ++j)
    {
      end_pts[j] = pts[I_SHIFT_EDGE[i][j]];
      vect_at_end_pts[j] = vector_at_pts[I_SHIFT_EDGE[i][j]];
    }

    if (isIntersected (end_pts, vect_at_end_pts, pt_union_indices))
    {
      // Indices of cells that contains points which will be connected to
      // create a polygon
      Eigen::Vector3i polygon[4];
      Eigen::Vector4f polygon_pts[4];
      int polygon_indices_1d[4];
      bool is_all_in_hash_map = true;
      switch (i)
      {
        case 0:
          polygon[0] = Eigen::Vector3i (index[0] - 1, index[1] + 1, index[2]);
          polygon[1] = Eigen::Vector3i (index[0] - 1, index[1], index[2]);
          polygon[2] = Eigen::Vector3i (index[0], index[1], index[2]);
          polygon[3] = Eigen::Vector3i (index[0], index[1] + 1, index[2]);
          break;
        case 1:
          polygon[0] = Eigen::Vector3i (index[0], index[1] + 1, index[2] + 1);
          polygon[1] = Eigen::Vector3i (index[0], index[1] + 1, index[2]);
          polygon[2] = Eigen::Vector3i (index[0], index[1], index[2]);
          polygon[3] = Eigen::Vector3i (index[0], index[1], index[2] + 1);
          break;
        case 2:
          polygon[0] = Eigen::Vector3i (index[0] - 1, index[1], index[2] + 1);
          polygon[1] = Eigen::Vector3i (index[0] - 1, index[1], index[2]);
          polygon[2] = Eigen::Vector3i (index[0], index[1], index[2]);
          polygon[3] = Eigen::Vector3i (index[0], index[1], index[2] + 1);
          break;
        default:
          break;
      }
      for (size_t k = 0; k < 4; k++)
      {
        polygon_indices_1d[k] = getIndexIn1D (polygon[k]);
        if (!occupied_cell_list_[polygon_indices_1d[k]])
        {
          is_all_in_hash_map = false;
          break;
        }
      }
      if (is_all_in_hash_map)
      {
        for (size_t k = 0; k < 4; k++)
        {
          polygon_pts[k] = cell_hash_map_.at (polygon_indices_1d[k]).pt_on_surface;
          surface_.push_back (polygon_pts[k]);
        }
      }
    }
  }
}
示例#4
0
double getDistSS(segment s1, segment s2)
{
	if (isIntersected(s1, s2)) return 0.0;
	return min(min(getDistPS(s2.p1, s1), getDistPS(s2.p2, s1)),
	    min(getDistPS(s1.p1, s2), getDistPS(s1.p2, s2)));
}