首页 > 其他 > 详细

生成 cone(锥体)

时间:2019-07-07 13:26:07      阅读:188      评论:0      收藏:0      [点我收藏+]

简介

生成 圆锥

代码

// 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;
}

生成 cone(锥体)

原文:https://www.cnblogs.com/eat-too-much/p/11145359.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!