Esempio n. 1
0
    void TestGetLocation()
    {
        ChastePoint<3> point(1.0, 2.0, 3.0);

        c_vector<double, 3>& point_location = point.rGetLocation();
        TS_ASSERT_EQUALS(point_location(1), 2.0);
        point_location(0) = 0;

        const c_vector<double, 3>& const_point_location = point.rGetLocation();

        for (int i=0; i<3; i++)
        {
            TS_ASSERT_DELTA(const_point_location[i], point[i], 1e-7);
        }
    }
Esempio n. 2
0
//qucikHull algorithm based on algorithm based on http://www.ahristov.com/tutorial/geometry-games/convex-hull.html java implimentation
vector<City> quickHull(vector<City> points_in){
	vector<City> convexHull(0);
	if(points_in.size() < 3){			//if our set is 3 point our hull is this set
							//		City A = points_in[0];	//Add the first point to the end so that we connect
							//		points_in.push_back(A);
		return points_in; 
	}
	int minCity = -1;
	int maxCity = -1; 
	int minX = INT_MAX; 
	int maxX = INT_MIN; 
	for (int i = 0; i < points_in.size(); i++){
		if(points_in[i].x() < minX){
			minX = points_in[i].x();
			minCity = i;
		}
	
		if(points_in[i].x() > maxX){
			maxX = points_in[i].x();
			maxCity = i;
		}
	}

	City A = points_in[minCity];
	City B = points_in[maxCity]; 
	convexHull.push_back(A);
	convexHull.push_back(B); 
	points_in.erase(points_in.begin() + minCity);
	points_in.erase(points_in.begin() + maxCity); 
	
	vector<City> left_set;
	vector<City> right_set;

	for (int i = 0; i < points_in.size(); i++) {
		City p = points_in[i]; 	
		if (point_location(A,B,p) == -1){
			left_set.push_back(p); 
		}
		else{ 
			right_set.push_back(p); 
		}
	}
	hull_set(A,B,right_set,convexHull);
	hull_set(B,A,left_set,convexHull);

	points_in.clear();
	for(int i =0; i < right_set.size(); i++){
		//right_set[i].Print("right set"); 
     		points_in.push_back(right_set[i]); 
	}
	      for(int i =0; i < left_set.size(); i++){
		//left_set[i].Print("left set"); 
		points_in.push_back(left_set[i]); 
	}

	return convexHull;
}
Esempio n. 3
0
//part of the quick hull algorithm based on http://www.ahristov.com/tutorial/geometry-games/convex-hull.html
void hull_set(City A, City B, vector<City> &set, vector<City> &hull){
	int insert_position =  find(hull.begin(), hull.end(), B) -  hull.begin();
	if (set.size() == 0)
		return;
	if (set.size() == 0){
		City p = set[0];
		//set.erase(set.begin()); 
		hull.insert(hull.begin() + insert_position, p); 
		return;
	}
	int dist = INT_MIN;
	int furthestCity = 0;
	for (int i = 0; i < set.size(); ++i){
		City p = set[i];
		int distance1 = distance(A,B,p);
		if (distance1 > dist){
			dist = distance1;
			furthestCity = i;
//			cout << "furthest index" <<furthestCity <<endl;
		}
	}

	City P = set[furthestCity];
//	set[furthestCity].Print("set");
//	for(int i = 0; i <set.size(); i++)
//		set[i].Print("set");
//	cout <<"furthest " <<furthestCity <<endl;
	hull.insert(hull.begin()+insert_position,P);
	set.erase(set.begin() + furthestCity);
//	 for(int i = 0; i <set.size(); i++)
//              set[i].Print("set");


	vector<City> leftSetAP(0); 
	for (int i = 0; i< set.size(); i++){
		City M = set[i];
		if(point_location(A,P,M)==1){
			//set.erase(set.begin() + i);
			leftSetAP.push_back(M);
		}
	}

	vector<City> leftSetPB(0);
	for (int i = 0; i< set.size(); i++){
		City M = set[i];	
		if(point_location(P,B,M)==1){
			//set.erase(set.begin() + i); 
			leftSetPB.push_back(M);
		}
	}
	
           
	hull_set(A,P,leftSetAP,hull);
	hull_set(P,B,leftSetPB,hull);

//	for(int i =0; i < leftSetPB.size(); i++){
  //              leftSetPB[i].Print("right set");
    //            set.push_back(leftSetPB[i]);
      //  }
        //for(int i =0; i < leftSetAP.size(); i++){
       //         leftSetAP[i].Print("left set");
         //       set.push_back(leftSetAP[i]);
       // }

}