the evil cube

This is the place for queries that don't fit in any of the other categories.

the evil cube

Postby luishp » Fri May 23, 2014 9:58 pm

Hi guys,

I am currently reading Introduction to Python Programming by John Zelle. I have gotten to the chapter about simulations and finished all the practice problems except one. This is the problem:

(Advanced) Here is a puzzle problem that can be solved with either some fancy analytic geometry (calculus) or a (relatively) simple simulation. Suppose you are located at the exact center of a cube. If you could look all around you in every direction, each wall of the cube would occupy 1/6 of your field of vision. Suppose you move toward one of the walls so that you are now half-way between it and the center of the cube. What fraction of your
field of vision is now taken up by the closest wall? Hint: use a Monte Carlo simulation that repeatedly “looks” in a random direction and counts how many times it sees the wall.

I would normally provide code along with this of what I have done but it's proven hard for me to even tackle this problem. I thought of how it would be done for a square instead of a cube.
# i would import math
# i would center a square of length 1 at (0, 0)
# i would make a point at (0, .5)
# from that point I would use
Code: Select all
angle = random() * 2 * math.pi

# Make a line going in the direction of the angle
# x = x + cos(angle)
y = y + sin(angle)
# and figure out which side of the square it intersects and record it

I'm not sure what exactly to do for a cube which is three dimensional. I'd really appreciate some direction.
Posts: 28
Joined: Wed Feb 05, 2014 12:44 am

Re: the evil cube

Postby mckryall » Mon May 26, 2014 10:29 pm

I think this forum is mainly for language-specific questions. I'd recommend going to a computer science or physics forum. The physicists could probably help you with the math, and the computer scientists could probably help you understand what they said from a programming perspective. If the people at Stack Overflow's forums don't go flag-happy on yo' question, you might be able to use that as a last resort. Come back to us when you have questions about getting this to work in python specifically. Good luck.
Python 2.7
Mac Mini (Desktop/server)
Macbook Air
Laptop w/ Ubuntu 14.04
Posts: 116
Joined: Sat Nov 23, 2013 6:13 pm

Re: the evil cube

Postby Kebap » Tue May 27, 2014 10:14 am

Hi luishp,

I like your idea of starting with 2d, then figuring out 3d solutions later. However, I would not use a random angle in 2d, as you are right, this is hard to copy to 3d.

Why don't you try using 2 random numbers, one for x dimension, one for y dimension. Then you can later add a random z dimension value, and be done with it (almost) :mrgreen:
Due to the reasons discussed here we are moving to on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 9 guests