//Finds a point between between the two distances to point p
Vec Cone::getRandomPoint(const Vec &p, double radius1, double radius2) const{
	fixRadius(radius1,radius2);

	double rad = radius();

	Vec point;
	double rv_choose = GLOBAL_mtrand.rand() * (SA_end + SA_cone);
	double x;
	double y;
	double num_try = 0;
	do{
		do{
			x = GLOBAL_mtrand.rand() * 2 * rad - rad;
			y = GLOBAL_mtrand.rand() * 2 * rad - rad;	
		}while(x * x + y * y > rad * rad);
		Vec xy_point = Vec(x,y,0);
		point = rotationMatrix * xy_point + origin;
		if(rv_choose <= SA_end){
			point += dir * height;
		}else{
			double r = (point - origin).Length();
			point += dir * height * r / rad ;
		}
		num_try++;
	}while(((point - p).Length() > radius1 || (point - p).Length() < radius2) && num_try < MAX_RANDOM_TRIES);

	if(x >= MAX_RANDOM_TRIES){
		return getRandomPoint(p,radius1);
	}

	return point;
}
Exemple #2
0
Point BaggageProcessor::GetServiceLocation()const
{
	
 	int ndx = getRandomPoint();
 	if( ndx < 0 )
 		ndx = random( m_vOccupiedID.size() );
 	return m_serviceCoords.getPoint (ndx);
}
/**
 * Generate a random polygon given maximum size and the number of points it
 * should be.
 */
static Polygon_t getRandomPolygon(int width, int height, int n_points)
{
    Polygon_t pg = {0};
    int i;

    for (i = 0; i < n_points; i++)
        pg.Points[i] = getRandomPoint(width, height);

    return pg;
}
Exemple #4
0
void
RandomCorrosion::timestepSetup()
{
  // Increase the number of points as the temperature differs from the reference
  Real factor = 1;
  if (_temperature > _ref_temperature)
    factor = 1 + (_temperature - _ref_temperature) * 0.1;

  // Generater the random points to apply "corrosion"
  _points.clear();
  for (unsigned int i = 0; i < _num_points * factor; ++i)
    _points.push_back(getRandomPoint());
}
Exemple #5
0
void TetrahedronTest::testTetrahedronBarycentricCoordinates() {
	const Geometry::Vec3d a(0.0, 0.0, 0.0);
	const Geometry::Vec3d b(30.0, 0.0, 0.0);
	const Geometry::Vec3d c(0.0, 30.0, 0.0);
	const Geometry::Vec3d d(0.0, 0.0, 30.0);
	const Geometry::Tetrahedron<double> tetrahedron(a, b, c, d);

	// Check the vertices.
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(1.0, 0.0, 0.0, 0.0), tetrahedron.calcBarycentricCoordinates(a).second);
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(0.0, 1.0, 0.0, 0.0), tetrahedron.calcBarycentricCoordinates(b).second);
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(0.0, 0.0, 1.0, 0.0), tetrahedron.calcBarycentricCoordinates(c).second);
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(0.0, 0.0, 0.0, 1.0), tetrahedron.calcBarycentricCoordinates(d).second);

	// Check the middle of edges.
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(0.5, 0.5, 0.0, 0.0),
						 tetrahedron.calcBarycentricCoordinates(Geometry::Vec3d(15.0, 0.0, 0.0)).second);
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(0.0, 0.5, 0.5, 0.0),
						 tetrahedron.calcBarycentricCoordinates(Geometry::Vec3d(15.0, 15.0, 0.0)).second);
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(0.5, 0.0, 0.5, 0.0),
						 tetrahedron.calcBarycentricCoordinates(Geometry::Vec3d(0.0, 15.0, 0.0)).second);
	CPPUNIT_ASSERT_EQUAL(Geometry::Vec4d(0.5, 0.0, 0.0, 0.5),
						 tetrahedron.calcBarycentricCoordinates(Geometry::Vec3d(0.0, 0.0, 15.0)).second);

	std::default_random_engine engine;
	std::uniform_real_distribution<float> dist(-10, 10.0);

	const double delta = 1.0e-3; // pretty inaccurate....

	for (int i = 0; i < 1000; ++i) {
		const Geometry::Tetrahedron<double> t(getRandomPoint(engine, dist), getRandomPoint(engine, dist),
											  getRandomPoint(engine, dist), getRandomPoint(engine, dist));
		if (t.calcVolume() < 10)
			continue;

		for (int j = 0; j < 100; ++j) {
			const Geometry::Vec3d point = getRandomPoint(engine, dist);
			const auto & coordinates = t.calcBarycentricCoordinates(point);
			if (!coordinates.first) { // degenerated
				break;
			}
			CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, t.calcPointFromBarycentricCoordinates(coordinates.second).distance(point),
										 delta);
		}
	}
}
Exemple #6
0
CCPoint LevelLayer::getSeerBornPoint(sActiveLevelConfig& config)
{
	int x = config.pos.x;
	int y = config.pos.y;
	if(m_pPhysicsLayer->isPointReachable(ccp(x, y)))
	{
		return config.pos;
	}

	if(m_bornPointList.size() > 0)
	{

		if(m_pPhysicsLayer->isPointReachable(m_bornPointList[0].point))
		{
			return m_bornPointList[0].point;
		}
	}


	return getRandomPoint();
}
Exemple #7
0
//implementation of the ransac algorithm
void ransac(){
	int i, j, k = 0, index_p1, index_p2, n_inliers = 0, n_inliers2;
	float slope, intercept;
	point inliers[1000], inliers2[1000];
	segment segTemp1, segTemp2;
	
	while(n_data >= 8){
		segments[n_segments].n_inliers = 0;
		
		//try to find a segment to different models
		for(i = 0; i < 500; i++){
			//get 2 random points of the data set
			index_p1 = getRandomPoint();
			index_p2 = getRandomPoint();
			while(index_p1 == index_p2 || data[index_p2].x == data[index_p1].x)
				index_p2 = getRandomPoint();
			
			//fit the model
			slope = (data[index_p2].y - data[index_p1].y) / (data[index_p2].x - data[index_p1].x);
			intercept = data[index_p1].y - (slope * data[index_p1].x); 
			
			//find the inliers
			findInliers(slope, intercept, inliers, &n_inliers);
			
			//find the biggest segment
			segTemp1 = getBiggestSegment(slope, intercept, inliers, &n_inliers);
			
			//there is no point in continue trying if the segment explains all data
			if(segTemp1.n_inliers == n_data){
				segments[n_segments] = segTemp1;
				break;
			}
				
			//apply regression to the segment until it gets less inliers
			segTemp2.n_inliers = 0;
			while(1){
				copyPoints(inliers2, inliers, n_inliers);
				n_inliers2 = n_inliers;
				
				segTemp2 = linearRegression(inliers2, &n_inliers2);
				
				if(segTemp2.n_inliers > segTemp1.n_inliers){
					segTemp1 = segTemp2;
					copyPoints(inliers, inliers2, n_inliers2);
					n_inliers = n_inliers2;
				}
				
				else
					break;
			}
			
			//compare with the biggest segments until now
			if(segTemp1.n_inliers > segments[n_segments].n_inliers)
				segments[n_segments] = segTemp1;
		}
		
		if(segments[n_segments].n_inliers >= 8){
			//remove inliers of the segment
			removeInliers(segments[n_segments]);
			n_segments++;
		}
		else
			break;
	}
}