コード例 #1
0
ファイル: main.cpp プロジェクト: gabyx/GRSFramework
int main()
{
  using T = double;
  T a = 1;                 // Left bound
  T b = 9;                 // Right bound
  T mu = 2;                // Mean
  T sigma = 3;             // Standard deviation
  T s;  // Output argument of rtnorm
  int K = 1e9;                  // Number of random variables to generate

    T res =0;
  //--- generate and display the random numbers ---
  std::cout<<"# x p(x)"<<std::endl;
  
  std::mt19937_64 m(5);
  rtnorm::truncated_normal_distribution<T> tnormal(mu,sigma,a,b);
  
    std::cout<<a<<" "<<b<<std::endl;
    std::cout<<mu<<" "<<sigma<<std::endl;

  for(int k=0; k<K; k++)
  {
    s = tnormal(m);
    res += s;
  }
  std::cout << res << std::endl;

  return 0;
}
コード例 #2
0
ファイル: scene.cpp プロジェクト: tiansijie/Sim-Bubble
//----------Sphere Class----------//
void Scene::Sphere::init_visualization()
{
	m_positions.clear();
	m_colors.clear();
	m_normals.clear();
	m_indices.clear();

	glm::vec3 mat_color(0.6f);
	unsigned int slice = 24, stack = 10;

	glm::vec3 tnormal(0.0f, 1.0f, 0.0f), tpos;
	tpos = m_center + m_radius * tnormal;

	m_positions.push_back(tpos);
	m_normals.push_back(tnormal);
	m_colors.push_back(mat_color);

	float theta_z, theta_y, sin_z;
	float delta_y = 360.0f / slice, delta_z = 180.0f / stack;
	//loop over the sphere
	for(theta_z = delta_z; theta_z < 179.99f; theta_z += delta_z)
	{
		for(theta_y = 0.0f; theta_y < 359.99f; theta_y += delta_y)
		{
			sin_z = sin(glm::radians(theta_z));

			tnormal.x = sin_z * cos(glm::radians(theta_y));
			tnormal.y = cos(glm::radians(theta_z));
			tnormal.z = -sin_z * sin(glm::radians(theta_y));

			tpos = m_center + m_radius * tnormal;

			m_positions.push_back(tpos);
			m_normals.push_back(tnormal);
			m_colors.push_back(mat_color);
		}
	}
	tnormal = glm::vec3(0.0f, -1.0f, 0.0f);
	tpos = m_center + m_radius * tnormal;

	m_positions.push_back(tpos);
	m_normals.push_back(tnormal);
	m_colors.push_back(mat_color);

	//indices
	unsigned int j = 0, k = 0;
	for(j = 0; j < slice - 1; ++j)
	{
		m_indices.push_back(0);
		m_indices.push_back(j + 1);
		m_indices.push_back(j + 2);
	}
	m_indices.push_back(0);
	m_indices.push_back(slice);
	m_indices.push_back(1);

	for(j = 0; j < stack - 2; ++j)
	{
		for(k = 1 + slice * j; k < slice * (j + 1); ++k)
		{
			m_indices.push_back(k);
			m_indices.push_back(k + slice);
			m_indices.push_back(k + slice + 1);

			m_indices.push_back(k);
			m_indices.push_back(k + slice + 1);
			m_indices.push_back(k + 1);
		}
		m_indices.push_back(k);
		m_indices.push_back(k + slice);
		m_indices.push_back(k + 1);

		m_indices.push_back(k);
		m_indices.push_back(k + 1);
		m_indices.push_back(k + 1 - slice);
	}

	unsigned int bottom_id = (stack - 1) * slice + 1;
	unsigned int offset = bottom_id - slice;
	for(j = 0; j < slice - 1; ++j)
	{
		m_indices.push_back(j + offset);
		m_indices.push_back(bottom_id);
		m_indices.push_back(j + offset + 1);
	}
	m_indices.push_back(bottom_id - 1);
	m_indices.push_back(bottom_id);
	m_indices.push_back(offset);

	if(m_indices.size() != 6 * (stack - 1) * slice)
		printf("indices number not correct!\n");
}