Пример #1
0
void make_triangles()
{
	delaunay2d_t* ret1 = delaunay2d_from(ball_pos,n);
	tri_delaunay2d_t* re2 = tri_delaunay2d_from(ret1);
	num_triangles = re2->num_triangles;
	tr.resize(num_triangles);
	for (int i = 0; i < re2->num_triangles; ++i){
		for (int j = 0; j < 3; ++j){
			tr[i].x[j] = re2->tris[3 * i + j];
		}
		tr[i].print();
	}

}
Пример #2
0
void  EditorScene::delaunay()
{

    /*
     typedef struct {
     /** input points count
     unsigned int	num_points;

     /** input points
     del_point2d_t*	points;

     /** number of triangles
     unsigned int	num_triangles;

     the triangles indices v0,v1,v2, v0,v1,v2 ....
     unsigned int*	tris;
     } tri_delaunay2d_t;
     */
    if (_points[_frameIndex].size() < 3) {
        return;
    }
    CCLOG("delaunay");
    _delPointsCount = 0;
    for (auto pair : _points[_frameIndex]) {
        _delPoints[_delPointsCount].x = pair.second->position.x;
        _delPoints[_delPointsCount].y = pair.second->position.y;
        _delPoints[_delPointsCount].pid = pair.first;
        _delPointsCount++;
    }

    auto res_poly = delaunay2d_from(_delPoints, _delPointsCount);
    auto res_tri = tri_delaunay2d_from(res_poly);


    _triangles[_frameIndex].clear();
    for (int i = 0; i < res_tri->num_triangles; i++) {
        auto tri = std::make_shared<EETriangle>();
        tri->a = _points[_frameIndex][res_tri->points[res_tri->tris[i*3]].pid];
        tri->b = _points[_frameIndex][res_tri->points[res_tri->tris[i*3+1]].pid];
        tri->c = _points[_frameIndex][res_tri->points[res_tri->tris[i*3+2]].pid];
        _triangles[_frameIndex].push_back(tri);
    }

    delaunay2d_release(res_poly);
    tri_delaunay2d_release(res_tri);
}