File:Barnes-Hut tree construction.png
Barnes-Hut_tree_construction.png (300 × 300 pixels, file size: 9 KB, MIME type: image/png, looped, 6 frames, 6.0 s)
Note: Due to technical limitations, thumbnails of this file will not be animated.
Captions
Summary
[edit]DescriptionBarnes-Hut tree construction.png |
English: An animation of Barnes-Hut tree construction for 48 particles distributed in a 2D box uniformly. |
Date | |
Source | Own work |
Author | Osanshouo |
Source code
[edit]This animation was created with the following Python source code.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
def cube_plot(ax, pos, level, idx):
d = 1./2**level
idx = [ idx[0]*d, idx[1]*d ]
count = np.sum((pos[:,0] - idx[0] >= 0)*(pos[:,0] - idx[0] < d)*(pos[:,1] - idx[1] >= 0)*(pos[:,1] - idx[1] < d))
if count == 0:
return count
color = cm.nipy_spectral(level/7.)
ax.plot([idx[0] , idx[0]+d], [idx[1] , idx[1] ], lw=1, color=color, alpha=1)
ax.plot([idx[0] , idx[0] ], [idx[1] , idx[1]+d], lw=1, color=color, alpha=1)
ax.plot([idx[0]+d, idx[0]+d], [idx[1] , idx[1]+d], lw=1, color=color, alpha=1)
ax.plot([idx[0] , idx[0]+d], [idx[1]+d, idx[1]+d], lw=1, color=color, alpha=1)
return count
def plot_rec(ax, pos, Lmax, level, idx):
count = cube_plot(ax, pos, level, idx)
if level +1 == Lmax:
return
if count > 1:
plot_rec(ax, pos, Lmax, level+1, [idx[0]*2, idx[1]*2])
plot_rec(ax, pos, Lmax, level+1, [idx[0]*2+1, idx[1]*2])
plot_rec(ax, pos, Lmax, level+1, [idx[0]*2, idx[1]*2+1])
plot_rec(ax, pos, Lmax, level+1, [idx[0]*2+1, idx[1]*2+1])
n = 48
np.random.seed(123)
pos = np.random.rand(n, 2)
for Lmax in range(1, 7):
fig = plt.figure( figsize=(3, 3) )
plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)
ax = fig.add_subplot(111, aspect=1)
ax.set_xlim([0, 1])
ax.set_ylim([0, 1])
plt.tick_params(axis='x',which='both',bottom=False,top=False,labelbottom=False)
plt.tick_params(axis='y',which='both',left=False,right=False,labelleft=False)
ax.scatter(pos[:,0], pos[:,1], c="indianred", s=5)
plot_rec(ax, pos, Lmax, 0, [0,0])
plt.savefig("bh{}.png".format(Lmax))
plt.close()
Licensing
[edit]- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 13:21, 25 May 2020 | 300 × 300 (9 KB) | Osanshouo (talk | contribs) | shrink to 300px | |
06:18, 24 May 2020 | 800 × 800 (23 KB) | Osanshouo (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on fr.wikipedia.org
- Usage on ja.wikipedia.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Software used |
---|