All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.
All our activities include solutions with explanations on how they work and why we chose them.
Write the function
generate_particle that generates a particle according to the previous definition. The function accepts three parameters
max_r which by default take the constants above and returns a tuple with
(x, y, r).
>>> generate_particle() (391.8484862104256, 92.86444985326192, 0.7227983373572378) >>> generate_particle(10, 10, 1) (5.184593462659739, 3.5388971902026602, 0.8641652792107458)
Generate a list of 1,000 random particles with the default values for
max_r, and store them in the
IMPORTANT: We'll validate your program by comparing it with the expected result of the same generation with
random.seed(10), so make sure you're using setting the correct seed before generating the particles.
Store the data from
particles in a CSV file named
particles.csv, with the header
x,y,r. You can use any method, including Pandas, manual CSV handling, etc. Here's an example header of the
x,y,r 399.98181628293946,214.4445273375573,2.890456505672352 144.2687624976512,406.66062567866004,4.117944362667227 457.43077373082303,80.11477825940983,2.603346798199623
Plot your particles in a dot-plot, each particle centered in
y and with a marker size of
Warning! don't change the
ax variables or the
It should look something like this:
calculate_particle_position receives two tuples, with the particle's and area's
x, y, r parameters and it should return the position of the particle (either completely contained, partially contained, or outside) in the form of an
Enum as its defined below:
from enum import Enum class ParticlePosition(Enum): PARTIALLY_CONTAINED = 1 COMPLETELY_CONTAINED = 2 OUTSIDE = 3
Read the particles from
particles.csv and plot them using special colors depending if the particle is fully contained, partially contained or not contained at all in the area A
(325, 225, 50)
If the particle is fully contained, it should be colored
green, if it's partially contained, it should be colored
red, while if it's outside, it should be black.
Your plot should look something like: