简介
生成 圆锥
代码
// 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!\n";
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;
}