Example #1
0
void Quadtree::makeQuadtree(std::vector<Particle> Particles, float x1, float x2, float y1, float y2, int maxSubTree)
{
	this->subNodes++;
	this->mass = 0.0f;
	this->cm_x = 0.0f;
	this->cm_y = 0.0f;	
	this->x1 = x1;
	this->x2 = x2;
	this->y1 = y1;
	this->y2 = y2;
	for (unsigned i=0; i<Particles.size(); i++)
	{
		Particle A = Particles[i];
		//is A in this quadrant?
		if (A.x >= x1 && A.x <= x2 &&
			A.y >= y1 && A.y <= y2)
		{
			this->Particles.push_back(A);
			this->mass += A.m;
			this->cm_x += A.m*A.x;
			this->cm_y += A.m*A.y;
		}
	}
	this->cm_x /= this->mass;
	this->cm_y /= this->mass;

	//if this quadrant has more than 1 particle, it must be subdivided
	if (this->Particles.size() > 3 && maxSubTree > 0)
	{
		//calc of the medium point on each axis
		float mx = (x1+x2)/2;
		float my = (y1+y2)/2;

		//create the eight sub Quadrants
		//and send the particles that are contained in this quadrant
		Quadrants.push_back(Quadtree(this->Particles,x1,mx,y1,my,maxSubTree-1));
		Quadrants.push_back(Quadtree(this->Particles,mx,x2,y1,my,maxSubTree-1));
		Quadrants.push_back(Quadtree(this->Particles,mx,x2,my,y2,maxSubTree-1));
		Quadrants.push_back(Quadtree(this->Particles,x1,mx,my,y2,maxSubTree-1));
	}
}
Example #2
0
int main(int argc, char** argv){
	Quadtree remora_gis = Quadtree();

	remora_gis.insert(-84.110250f, 9.933845f, 0x1E1);
	remora_gis.insert(-84.108877f, 9.938325f, 0x2DF);
	remora_gis.insert(-84.098514f, 9.937848f, 0x2D4);
	remora_gis.insert(-84.098266f, 9.935712f, 0x2D2);
	remora_gis.insert(-84.099593f, 9.935712f, 0x2D6);
	remora_gis.insert(-84.099605f, 9.932733f, 0x2D2);


	remora_gis.insert(9.64f, 84.19f, 0x83);
	remora_gis.insert(39.10f, 18.99f, 0x47);

	

	vector<Data> test_points;
	/*
	
	get_coordinates();
	if ( abs(lat_1 - lat_0) > los || abs(lat_1 - lat_0) > los){
		lat_0 = lat_1;
		lon_0 = lon_1;
		test_points = remora_gis.nearest_points(lat[i], lon[i], los);
	}
	point_in_area(test_points, lat_0, lon_0);

	*/

	//-84.104447f, 9.935764f -- 1
	//-84.110101f, 9.936192f -- 0 evalúa a 1 por área más grande de lo necesario
	//-84.113754f, 9.937331f .. 0

	float lat[] = {9.935764f, 9.936192f, 9.937331f};
	float lon[] = {-84.104447f, -84.110101f, -84.113754f};
	float los = 0.005f;

	for(int i = 0; i < 3; i++){
		test_points = remora_gis.nearest_points(lat[i], lon[i], los);
		cout << "\nPuntos adyacentes para " << lon[i] << ", " << lat[i] << ": " << test_points.size() << "\n\n";
		point_in_area(test_points, lat[i], lon[i]);
	}


	return 0;
}