Notifications
Clear all

[Closed] Collision Detection Algorithm

ok, but where should I start with this algorithm? Should I calculate the center of the scene and start with the sphere, which is nearest to the center or does it not matter where I start?

for this example doesn’t matter

btw I made a test and for
r/2 I get 52 iteration and with r/1 58

if you want to use the density calculate the density of the sphere by suming the distance between spheres closer than r*2 for example.
then sort the sphere by 1/density descendent or just by density ascendent

and when you will collide the sorted spheres it will move from center out,

but here you see that you need 2 n*n passes

you can also use somehow density information to get the substeps… so where the density is higher you will want to go slower so you will not get jumpy movement forward and backward

you can also use grids with r*2 width, for quicker collision find

Hi!
It doesn’t work. It doesn’t comes to an end
My code is the following:


int Collision_Function_cf2(int t, const int object_number, int* object_field, , Point3 **animation_frames, float *radius) 
{
	

	int remember = 0;

 
	Point3 current_vector;
	Point3 current_vector1;
	float vector_length;
	Point3 vector_difference;
	int current_index;
	int index2;



	for(int i = 0; i < object_number; i++)
	{
		current_index = object_field[i];

		for(int j = i; j < object_number; j++)
		{
			index2 = object_field[j];
			if(current_index != index2)
			{
					
					
				current_vector = animation_frames[index2][t] - animation_frames[current_index][t];
				vector_length = sqrt((current_vector.x * current_vector.x) + (current_vector.y * current_vector.y) + (current_vector.z * current_vector.z));

				if(vector_length < (radius[index2] + radius[current_index]))
				{
					current_vector1 = current_vector / vector_length;
					current_vector = -current_vector1;
					vector_length = radius[index2] + radius[current_index] - vector_length;
					//vector_length = vector_length + (0.05 * vector_length);

					
					
							
					vector_length = (vector_length / 2) + 0.01;
					if(vector_length > (radius[current_index] / 5))
					{
						vector_length = radius[current_index]/5;
					}

					animation_frames[current_index][t] = animation_frames[current_index][t] + (current_vector * vector_length);
					animation_frames[index2][t] = animation_frames[index2][t] + (current_vector1* vector_length);
					control_array[current_index][t] = 1;
					control_array[index2][t] = 1;


				}
			}
		}
	}
			
	for(int i = 0; i < object_number; i++)
	{
		current_index = object_field[i];

			for(int k = i; k < object_anzahl; k++)
			{
				index2 = object_number[k];
				if(index2 != current_index)
				{
						
						
					if(vector_length < (radius[index2] + radius[current_index]))
					{
						remember = 1;
					}
						
				}

			}
	}

						

		
	
	return remember;
}





and then in my main program I call this function again if remember = 1.

Page 2 / 2