Jump to content

How is asteroid mass calculated?


Recommended Posts

I recently attempted my first-ever asteroid redirect, with an A-class asteroid that was approaching Kerbin. Rendezvous was successful, but once I was attached to the asteroid, I realised that its mass was 150 tonnes - far more than my expected maximum of 10 tonnes. I found that this is a bug that was already on the tracker (Bug #9392) - it seems that all asteroids are spawning with a mass of 150 tonnes regardless of physical dimensions.

With little information available, I want to have a go at diagnosing the problem, and possibly at creating a mod to remedy it. My question is, how is the mass of an asteroid calculated? How is it dependent on class/size/shape, what algorithm is used to come up with it? I can see in the PotatoRoid part.cfg file that the default mass is 150 tonnes, so presumably something that used to happen on asteroid generation is no longer happening.

(As a secondary question, have many people noticed this bug before? I feel like if it was a widespread problem I would have found more threads about it.)

Link to comment
Share on other sites

Another possible cause is something new overwriting the mass after the asteroid has been generated. Did they mention something about reloading assets while the game is running to speed up development and testing in dev notes before 1.1? Such a feature could do it.

As to how the mass is calculated, I would hazard a guess that they would calculate the volume of the asteroid and multiply it by a constant density. Throw in a random factor for ore content and you are all set. One could calculate the exact volume from the generated mesh, but since real asteroids are not all exactly the same density you would get away with estimating it from the average radius with the sphere volume formula. If you cannot access the average radius used to generate the mesh you may have to estimate that too. Averaging a few random vertices from the mesh should get you close enough.

Link to comment
Share on other sites

8 hours ago, monophonic said:

As to how the mass is calculated, I would hazard a guess that they would calculate the volume of the asteroid and multiply it by a constant density.

My own guess (based on no information whatsoever, other than that it's how I would code it if I were the one writing the feature) is that you've got it backwards, and that the mass isn't calculated, it's assigned.

In other words, an algorithm something like this:

  1. Oh, I need to generate a new random asteroid.
  2. Pick an asteroid class.
  3. For that asteroid class, randomly pick a mass, based on some allowed range that's configured somewhere.
  4. Having picked a mass, now generate a mesh for it, based on the physical size defined for that asteroid class, and maybe taking the mass into account as a scale multiplier.

Of course, that doesn't explain how you could get a Class A asteroid with a mass of 150 tons.  That sounds like a bug to me.  Have you reported it?

Link to comment
Share on other sites

I'm encountering the same issue, and I was going to report it, but I wasn't sure where you go now to report bugs.

I can add something to this, it did NOT effect my Emiko Station Asteroid!  I just went and rechecked and that one is still weighing in at well over 3,000t. But when I checked a couple newly discovered dres-deroids, no matter what the class, they weighed in at 150t.  So this makes me think it's only happening to newly spawned asteroids.

Edited by Just Jim
Link to comment
Share on other sites

8 hours ago, monophonic said:

As to how the mass is calculated, I would hazard a guess that they would calculate the volume of the asteroid and multiply it by a constant density. Throw in a random factor for ore content and you are all set. One could calculate the exact volume from the generated mesh, but since real asteroids are not all exactly the same density you would get away with estimating it from the average radius with the sphere volume formula. If you cannot access the average radius used to generate the mesh you may have to estimate that too. Averaging a few random vertices from the mesh should get you close enough.

37 minutes ago, Snark said:

My own guess (based on no information whatsoever, other than that it's how I would code it if I were the one writing the feature) is that you've got it backwards, and that the mass isn't calculated, it's assigned.

Though I initially thought that it would be assigned, I did see the following lines in the config file:

Quote

MODULE
{
    name = ModuleAsteroid    
    density = 0.03
}

That might indicate that an actual calculation takes place, but I'm not an expert so I don't know how/whether that's used.

41 minutes ago, Snark said:

That sounds like a bug to me.  Have you reported it?

It's already on the tracker (linked in the OP). My experiences match exactly those described in the bug report (all asteroids of all classes spawn with mass 150t), so I didn't have any information to add.

Link to comment
Share on other sites

Nope it's not a bug.. it's a feature !!

Look in the folder:- GameData\Squad\Parts\Misc\PotatoRoid

You'll find only one asteroid 'part' file.. and it's mass is set to 150 tons

...

// --- standard part parameters ---
mass = 150
dragModelType = default

...

Link to comment
Share on other sites

11 minutes ago, ColKlonk said:

Nope it's not a bug.. it's a feature !!

Look in the folder:- GameData\Squad\Parts\Misc\PotatoRoid

You'll find only one asteroid 'part' file.. and it's mass is set to 150 tons

...

// --- standard part parameters ---
mass = 150
dragModelType = default

...

ok, but I have an installation of 0.90 and the parameter is the same, but the asteroids appeared in various sizes and masses, not now

Link to comment
Share on other sites

23 minutes ago, ColKlonk said:

Nope it's not a bug.. it's a feature !!

Look in the folder:- GameData\Squad\Parts\Misc\PotatoRoid

You'll find only one asteroid 'part' file.. and it's mass is set to 150 tons

...

// --- standard part parameters ---
mass = 150
dragModelType = default

...

That's what I was referencing in my original post. It definitely is a bug, asteroids have previously always generated with different masses.

Link to comment
Share on other sites

As far as I know, the asteroid mass is always calculated based on the density and a rough estimate of the asteroid volume*. I don't think the resource content is taken into account.

I have not (yet) seen the always-150-tons bug myself; in my tests asteroids always had generated-looking masses.

* I should add an extra comment based on the bug report linked from the OP: the asteroid mass is calculated when the asteroid first enters physics range. Unloaded asteroids will always mass 150 tons, because the asteroid's shape hasn't been generated yet. Hope this clarifies the "is it/isn't it a bug" questions.

Edited by Starstrider42
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...