在三角形面上均匀采样

综述

在面片上均匀采样

结果

在这里插入图片描述

代码

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_3.h>
#include <CGAL/Weighted_point_3.h>
#include <iostream>
#include <fstream>
#include <set>
#include <cmath>
#include <string>
#include <map>
#include<vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3                                     Point;

using namespace std;

vector<Point> result;
void createRandomPts(vector<Point> con, int maxCount)
{
    double cx = (con[0][0] + con[1][0]  +con[2][0])/3;
    double cy = (con[0][1] + con[1][1]  +con[2][1])/3;
    double cz = (con[0][2] + con[1][2]  +con[2][2])/3;


    for (int i = 0; i < 3; i++)
    {
        int count = 0;

        int index1 = i, index2 = i + 1;
        if (i == 3 - 1)
        {
            index1 = 0; index2 = 3 - 1;
        }

        srand(time(NULL));

        while (count < maxCount)
        {
            double ab1 =  con[index1][0] - cx;
            double ab2 =  con[index1][1] - cy;
            double ab3 =  con[index1][2] - cz;
            double ac1 =  con[index2][0] - cx;
            double ac2 =  con[index2][1] - cy;
            double ac3 =  con[index2][2] - cz;
            float x = rand() / (RAND_MAX + 0.0);
            float y = rand() / (RAND_MAX + 0.0);
            float x1, y1;

            if (x + y > 1)
            {
                x1 = 1 - x; y1 = 1 - y;
            }
            else
            {
                x1 = x; y1 = y;
            }

            Point pt(cx+ab1*x1+ac1*y1,
                    cy+ab2*x1+ac2*y1,
                    cz+ab3*x1+ac3*y1);

            result.push_back(pt);
            count++;
        }

    }

}
int  main(){
    Point p1(0,0,0);
    Point p2(1,0,0);
    Point p3(0,1,0);
    vector<Point>con;
    con.push_back(p1);
    con.push_back(p2);
    con.push_back(p3);
    createRandomPts(con,60);
    for (int j = 0; j < result.size(); ++j) {
        cout << "v " << result[j] << endl;

    }
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页