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_x
, max_y
, max_r
which by default take the constants above and returns a tuple with (x, y, r)
.
Example:
>>> 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_x
, max_y
and max_r
, and store them in the particles
variable.
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 particles.csv
file:
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 x
, y
and with a marker size of r
.
Warning! don't change the fig
, or ax
variables or the figsize
defined.
It should look something like this:
The function 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: