Coding Challenge 176: Buffon's Needle

preview_player
Показать описание


References:

Related Coding Challenges:

Timestamps:
0:00 Happy Pi Day 2023!
0:45 Introduce Buffon's Needle
1:40 Unpack the math
4:40 Let toothpick fall at an angle
7:08 The probability that the toothpick crosses the border
7:27 Uniform probability density function
8:12 Illustrate the probability with a graph
10:49 Approximating the value of Pi
11:11 Calculating the area under the curve
12:48 Resources for Buffon's Needle
13:28 Start Coding
13:53 Draw vertical lines
14:20 Add a toothpick
15:02 Draw background in setup
15:57 We have to use the built-in value of Pi
17:00 Find the closest column
17:22 Determine if the toothpick intersects the column
18:10 Rotate the line relative to the y-axis
18:50 Draw the toothpick as a vertical line
19:40 Improve the visuals
20:48 Approximate the value of Pi using the probability that a toothpick intersects a column
23:45 Suggestions for variations
24:08 New Passenger Showcase page on the Coding Train website
24:38 Easter egg

Editing by Mathieu Blanchette
Animations by Jason Heglund
Pi Day Song by Will from America
Music from Epidemic Sound

#piday #pi #buffonsneedle #buffon #p5js #javascript
Рекомендации по теме
Комментарии
Автор

Just when the world needed him most, he returned...

jayjasespud
Автор

I gotta say these new whiteboard animations you have going on are really impressive

Daimondz
Автор

To specify rotation of the toothpick without relying on Pi in the code, you could generate two random points! The first random point would be inside the canvas, and would define the location of the center of the toothpick. The second point could fall anywhere, even outside the canvas. The second point is used to define a vector, which will guide the rotation of the toothpick. Draw a construction line connecting the center of the toothpick with the second random point, then draw the toothpick with the appropriate length along that construction line. This should get you random orientations without relying on already knowing the value of pi!

evanbarnes
Автор

16:06 - I believe that if you used `angleMode(DEGREES);` in your setup, you could specify the angles with -180 to 180 and thereby removing the dependency on PI!

Plokmin
Автор

The most underrated teacher i’ve ever learned from, Thank you for all the time you spent through out the years on this amazing content!

rayantovi
Автор

12:00 it is an image, but there is no greenscreen... and the image is between him and board which he interacts with

sergodobro
Автор

7:25 I've heard of falling angels, but falling angles are new to me :)
Excellent video!

_rlb
Автор

I love this tradition of you calculating Pi in many different ways!

raphaelfrey
Автор

Your enthusiasm and thorough explanations are unlike anything I've seen before. Thank you so much!

chad
Автор

I love this channel. Super interesting stuff and excellent delivery. Congrats!!!!

rockapedra
Автор

I can only grasp half of this, but I'm enjoying myself anyway. What enthusiasm!

mfiorentino
Автор

I just found your channel a week ago and it’s been helping me with python. So glad you are still active on YouTube.

EricaRuns
Автор

Love your videos. Youre an absolute treasure.

vihaanmenon
Автор

A possible way to pick a random angle without referencing pi whatsover: use a uniform distribution over a HUGE interval (or take the uniform distribution on (0, 1) and map it to a large interval).

I haven't directly tested this way of rng, but here's why I think it should work. Let's write the total width of our interval in the form z = 2*pi*N + x, where N is a large enough natural number, and x any real number between 0 and 2*pi. If we had x=0, then we are picking the angles on an interval of with 2*pi*N, which for the purposes of rotating the toothpicks is indistingushable from picking from an interval of width just 2*pi.

When x is not zero, the probability of picking the angle in the "wrong" part of the interval is equal to x / (2*pi*N + x). This number is vanishing small, the larger we pick N -- we don't directly pick N, but a number very large number z = 2*pi*N+x to make sure tha N is really, really big.

xnick_uy
Автор

19:07 there it is, near the center of the canvas: PI! Challenge completed!

dasten
Автор

First of all: Happy pi day from Spain. I want to propose a problem. How about an extension to 3D of this problem. Suppose we place random needles on the space at random points with some length and two angles defining the orientation. What is the probability of a needle to cross two parallel planes at unit distance one from each other. What if instead of two planes we take a cube? What is the probability of a needle crossing one side of the unit cube. Hint: Does that probability involve pi? The result may be surprising 😉

malcom
Автор

Loved the video! Thanks for featuring my sketch!!

DipamSen
Автор

To get a uniform angle in (0, 2pi) you could generate uniform x, y in (0, 1) until x^2+y^2<1 and then use atan(x/y) as your angle.

This works as by throwing away the x, y with x^2+y^2>=1 you essentially create a uniform distribution on the circle, and there the angle is uniformly distributed.

nurn
Автор

14:17 That seems like the best choice, and not because it would look more interesting, but because you wouldn't eschew the results.
If you limit to just 90º the toothpicks will have "one" chance to be at an angle 0º < θ < 90º, one chance to land vertically and one chance to land horizontally, if you expand to 180º that changes to 2 chances "at an angle", two chances horizontally and one chance vertically, but since they can in reality land at whatever angle between 0º and 360º, the chances are actually four times "at an angle", two times horizontally and two times vertically.

It shouldn't, I believe, make much of a difference, but since it's the same to use a full circle as it is to use just 1/4 of one, go for the more accurate simulation.

pedro_
Автор

I really would like to have you back for the coding challenges with p5js.

ensabinha