5
$\begingroup$

In my n-body simulation I would like to color the particles in way which corresponds to the magnitude of the net force acting on them.

This is so that I can confirm visually that the particles closer to the center of a galaxy have higher accelerations (so for example particles near the rim of a galaxy are lighter colored, and the core is red).

Let P be a particle. If F is the magntitude of the net force acting on P, the idea is to calculate s=F/F_max where F_max is the maximum possible force between two particles (which exists since my simulation uses gravitational softening). Since s is a number between 0 and 1, I can associate to P an HSV color by fixing saturation and value, and setting hue=s.

The issue: because the gravitational force scales as 1/r^2 the mapping of F to s is not linear. The result is that, when their are few particles (N<50), the color of a particle seem to change only if it becomes locked in a binary (in a bound system of two particles which are very close to eachother). The binaries are easy to identify because they blink (default color when they are at maximal distance, another color when they are at minimal distance).

For N=10,000 the result is pretty at least, but I'm not sure how realistic it is.

enter image description here

So how should I map the force to a color in a realistic way? My goal would be to get something more like this:

enter image description here

$\endgroup$
  • $\begingroup$ Can you explain a few things? What's your color scale? Are you using the full hue range? (For example 0° = red, 60° = yellow, 120° = green, 180° = cyan, 360° = red?) Also, what makes you think what you're seeing isn't correct or on the right track? Do you know how many particles were used in the "goal" picture? Given what you said about the colors for small N, it seems feasible that by using a larger N you might get coloring more like the goal. But I'm just speculating. $\endgroup$ – user1118321 Sep 23 '17 at 16:18
  • $\begingroup$ I am using HSV colors where each parameter is between 0 and 1. I fix S and V to be 1 and H corresponds to the magnitude of the force. Then I convert HSV colors to RGB and multiply each parameter by 255 because pygame display only accepts RGB colors in this format. $\endgroup$ – Joshua Benabou Sep 23 '17 at 19:12
  • $\begingroup$ What I mean is are you using the full Hue range from 0° to 360°? If so, you might want to limit it to either 0-180° or 0-270°. Otherwise, things with very large force look the same as things with very little force, since the hues wrap around at 360°. $\endgroup$ – user1118321 Sep 23 '17 at 19:15
  • $\begingroup$ @user1118321: you might be right that the colors in my sim look weird because I don't have the same conditions as in the "goal" sim. We are both using 10,000 particles, but my initial conditions are randomized positions and velocities, which will never produce a galaxy like the one shown above. We need to give the system some initial angular momentum to get a rotating galaxy. So I will see what happens by using proper initial conditions. I was just wondering if there was anything else I should be considering w.r.t the color scaling, or anything I'm doing that is obviously wrong. $\endgroup$ – Joshua Benabou Sep 23 '17 at 19:15
  • $\begingroup$ @user1118321: as I said, I use HSV colors where each parameter is from 0-1 instead of 0-360. If I set S and V to 1, and let H vary between 0 and 1, there is not this problem of wrapping around. H=0 gives red while H=1 gives green. $\endgroup$ – Joshua Benabou Sep 24 '17 at 17:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.