Collision of Planets: FF & AS Destruction

In summary, a collision of planets occurs when two or more planets in a solar system collide due to intersecting orbits. While it is possible for a collision to happen in our solar system, the chances are slim due to the stable orbits and vast distances between planets. If Earth were to collide with another planet, it would result in catastrophic destruction and scientists use telescopes and simulations to study and potentially prevent collisions.
  • #1
mathmari
Gold Member
MHB
5,049
7
Hey! :eek:

I want to write a function for the collision of the free-floating planet with identifier ffp and the planet with identifier as. The collision has as a result the destruction of both planets. Specifically, the free-floating planet with identifier ff will be deleted from the free-floating tree to which it belonged, but also the planet with identifier <as> will be deleted from the tree of asteroids of the planetary system that it belonged to.The structures are the following:

Code:
struct starsy {
	int         ss;       /* The star system identifier. >0 */
	plansys_t *plasy;    /* Pointer to the first element in the list of the planetary system */
	plansys_t *Sentinel; /* Pointer to the sentinel node of the list of the planetary system */
	asteroid_t   *ff;   /* The free-floating planets tree  */
};struct plansys {
	int           solid;         /* The planetary system identifier. >0 */
	asteroid_t     *asteroids;     /* Pointer to the first node in the list of the asteroids */
	asteroid_t     *asentinel;   /* Pointer to the sentinel node of the asteroids tree */
	plansys_t      *next;        /* Pointer to the next node in the list of the planetary systemt */
};struct asteroid {
	int           as;         /* The asteroid identifier. >0 */
	int           gap;    /* The absolute gap from the object of the planetary system */
	asteroid_t     *PARENT;      /* Pointer to the parent node in the asteroids tree */
	asteroid_t     *LC;          /* Pointer to the left child in the asteroids tree */
	asteroid_t     *RC;          /* Pointer to the right child in the asteroids tree */
};

starsy_t StarS[N];     /*The array of the star systems, it is an array of lists */
 
int Sfreep;      /*An index to the first free position in the array of the star systems*/

I have done the following:

Code:
int asteroid_freefloating_boom(int ffp, int as) {
	int i, k=-1, j, g=-1;
	asteroid_t *p=NULL;
	plansys_t *q=NULL; 
	for(i=0; i<Sfreep; i++){
			q=StarS[i].plasy;
			while(q->asteroids != NULL  && q->asteroids->as != as){
				if(q->asteroids->as < as ){
					q->asteroids=q->asteroids->RC;
				}
				else{
					q->asteroids=q->asteroids->LC;
				}
			}
			if(q->asteroids != NULL && q->asteroids->as==as){
				k=i;
				
			}
	}

	if(k == -1){
		return 0;
	}
	
	p=StarS[k].plasy->asteroids;
	
	
	for(i=0; i<Sfreep; i++){
			while(StarS[i].ff!= NULL && StarS[i].ff->as != as){
				if(StarS[i].ff->as < as){
					StarS[i].ff=StarS[i].ff->RC;
				}
				else if(StarS[i].ff->as > as){
					StarS[i].ff=StarS[i].ff->LC;
				}
			}
			if(StarS[i].ff->as==as){
				k=i;
				
			}
	}
	
	if(k == -1){
		return -1;
	}
	
	if(g == -1){
		return -1;
	}
	

	return 0;
}

Is this correct?? (Wondering)
 
Technology news on Phys.org
  • #2


I cannot provide a definitive answer on whether your code is correct or not without further testing and analysis. However, here are some suggestions that may help improve your function:

1. Use meaningful variable names: Instead of using single letter variables like i, k, and j, use more descriptive names that reflect their purpose in the code. This will make your code easier to read and understand.

2. Use comments: Adding comments throughout your code can help explain your thought process and make it easier for others to understand your code.

3. Consider using a different data structure: Your current approach requires looping through multiple arrays and lists, which can be time-consuming and inefficient. Consider using a different data structure, such as a hash table or binary search tree, which can make searching for specific elements faster.

4. Test for edge cases: Make sure your function can handle different scenarios, such as when the free-floating planet or asteroid is not found, or when there are multiple occurrences of the same identifier in the data structures.

Overall, it is important to thoroughly test and debug your function to ensure it works correctly in all cases.
 

Related to Collision of Planets: FF & AS Destruction

1. What is a collision of planets?

A collision of planets occurs when two or more planets in a solar system collide with one another due to their orbits intersecting. This can result in destruction and major changes to the planets' physical characteristics.

2. Can a collision of planets happen in our solar system?

While it is highly unlikely, a collision of planets can happen in our solar system. However, the chances of it occurring are extremely small due to the vast distances between planets and their stable orbits.

3. What would happen if Earth collided with another planet?

If Earth were to collide with another planet, it would result in catastrophic destruction of both planets. The impact would release an enormous amount of energy, causing massive earthquakes, tsunamis, and altering the Earth's atmosphere and surface.

4. How do scientists study the possibility of a collision of planets?

Scientists use advanced telescopes and simulations to study the movements and orbits of planets in order to determine the likelihood of a collision. They also analyze data from past collisions in our solar system to better understand the potential effects of such an event.

5. Is there any way to prevent a collision of planets?

It is not currently possible to prevent a collision of planets. However, scientists and astronomers closely monitor the movements of planets and their orbits to predict and potentially prevent any potential collisions in the future.

Similar threads

  • Programming and Computer Science
Replies
20
Views
4K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
4
Replies
119
Views
15K
  • Programming and Computer Science
Replies
1
Views
2K
  • Astronomy and Astrophysics
Replies
2
Views
1K
  • Astronomy and Astrophysics
Replies
4
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Astronomy and Astrophysics
Replies
10
Views
5K
Back
Top