生成 cone(锥体)

简介

生成 圆锥

代码

// CreateCone.cpp: 定义控制台应用程序的入口点。
//

#include <iostream>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include<cmath>
#include "AddPolygon.h"
#define pi 3.1415926
using namespace std;
typedef OpenMesh::TriMesh_ArrayKernelT<> MyMesh;

MyMesh* CreateCone(int edge, double height) {
	MyMesh * cone = new MyMesh;
	MyMesh::VertexHandle * bottom = AddPolygon(*cone, edge, -height / 2, false);
	MyMesh::VertexHandle vhandle = (*cone).add_vertex(MyMesh::Point(0, 0, height/2));
	for (int i = 0; i < edge; i++) {
		int next = (i + 1) % edge;
		std::vector<MyMesh::VertexHandle>face_vhandles;
		face_vhandles.push_back(bottom[i]);
		face_vhandles.push_back(bottom[next]);
		face_vhandles.push_back(vhandle);
		(*cone).add_face(face_vhandles);

	}
	return cone;
}


int main()
{
	int edge;
	double height;
	cout << "Please input edge and height!
";
	cin >> edge >> height;
	MyMesh *mesh = CreateCone(edge, height);
	try
	{
		if (!OpenMesh::IO::write_mesh((*mesh), "output3 .off")) {
			std::cerr << "Cannot write mesh to file ' output3 .off ' " << std::endl;
			return 1;
		}
	}
	catch (std::exception&x) {
		std::cerr << x.what() << std::endl;
		return 1;
	}
    return 0;
}


Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/11145359.html