Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpmoxhay <pmoxhay@earthlink.net>2009-05-27 18:07:54 (GMT)
committer pmoxhay <pmoxhay@earthlink.net>2009-05-27 18:07:54 (GMT)
commit7fc6d253b28e78bf9c878479bec99a4a228fcdeb (patch)
tree910d168844d47fa2ac1f48c36790660720fed8d1
parente35f07931d3fd0989bb371f5fe33185229ed9aec (diff)
Increased number of volume problems.
-rw-r--r--volumeobject.py16
-rw-r--r--volumeproblem.py174
2 files changed, 153 insertions, 37 deletions
diff --git a/volumeobject.py b/volumeobject.py
index de0c8f3..88599ff 100644
--- a/volumeobject.py
+++ b/volumeobject.py
@@ -47,9 +47,7 @@ class VolumeObject(MovableObject):
self.contains_water = False
self.full = False
-
- #print "VolumeObject constructor: volume =", self.volume
-
+
def calculate_volume(self):
return (math.pi * self.height / 3.0) * \
(self.lower_radius * self.lower_radius + self.lower_radius * self.upper_radius + self.upper_radius * self.upper_radius)
@@ -59,29 +57,21 @@ class VolumeObject(MovableObject):
(self.lower_radius * self.lower_radius + self.lower_radius * self.water_upper_radius + self.water_upper_radius * self.water_upper_radius)
def fill_to_given_volume(self, volume):
- #print "******fill_to_given_volume called: volume =", volume
a = (self.upper_radius - self.lower_radius)**2
- #print " a =", a
b = 3.0 * self.lower_radius * (self.upper_radius - self.lower_radius)
- #print " b =", b
c = 3.0 * self.lower_radius ** 2
- #print " c =", c
d = -3.0 * volume/(math.pi * self.height)
- #print " d =", d
solution = self.cubic(a, b, c, d)
- #print " solution =", solution
- if volume <= 0.0:
+ #if volume <= 0.0:
+ if volume <= 0.0001:
self.water_height = 0.0
self.water_upper_radius = self.lower_radius
else:
self.water_height = solution[0] * self.height
self.water_upper_radius = self.lower_radius + self.water_height * (self.upper_radius - self.lower_radius)/self.height
- #print "******fill_to_given_volume called: self.upper_radius =", self.upper_radius
- #print "******fill_to_given_volume called: self.water_upper_radius =", self.water_upper_radius
-
self.water_volume = self.calculate_water_volume()
# Solve the cubic equation.
diff --git a/volumeproblem.py b/volumeproblem.py
index 3c031d4..d6a54ed 100644
--- a/volumeproblem.py
+++ b/volumeproblem.py
@@ -67,47 +67,173 @@ class VolumeProblem(Problem):
# Define the various problems.
if problem_number == 0:
+ # First volume is a cylinder.
self.height1 = 230.0
self.lower_radius1 = 75
self.upper_radius1 = 75
- self.height2 = 200
+
+ # Second volume is a cone.
self.lower_radius2 = 60
self.upper_radius2 = 100
volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(volume1, self.lower_radius2, self.upper_radius2)
volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
- #print "volume1 =", volume1
- #print "volume2 =", volume2
- new_height2 = self.calculate_height_for_equal_volume(volume1, self.lower_radius2, self.upper_radius2)
-
- #print "new_height2 =", new_height2
-
- new_volume2 = self.calculate_volume(new_height2, self.lower_radius2, self.upper_radius2)
- #print "new_volume2 =", new_volume2
- self.height2 = new_height2
-
+
elif problem_number == 1:
- self.height1 = 160
- self.lower_radius1 = 95
- self.upper_radius1 = 95
- self.height2 = 200
+ # First volume is a cylinder.
+ self.height1 = 230.0
+ self.lower_radius1 = 75
+ self.upper_radius1 = 75
+
+ # Second volume is a cone.
self.lower_radius2 = 60
self.upper_radius2 = 100
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(1.1 * volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
elif problem_number == 2:
- self.height1 = 232.3
- self.lower_radius1 = 75
- self.upper_radius1 = 75
- self.height2 = 200
- self.lower_radius2 = 70
- self.upper_radius2 = 116
- else:
- self.height1 = 232.3
+ # First volume is a cylinder.
+ self.height1 = 230.0
self.lower_radius1 = 75
self.upper_radius1 = 75
- self.height2 = 200
+
+ # Second volume is a cone.
self.lower_radius2 = 60
self.upper_radius2 = 100
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(0.9 * volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 3:
+ # First volume is a cylinder.
+ self.height1 = 200.0
+ self.lower_radius1 = 90
+ self.upper_radius1 = 90
+
+ # Second volume is a cylinder.
+ self.lower_radius2 = 100
+ self.upper_radius2 = 100
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 4:
+ # First volume is a cylinder.
+ self.height1 = 200.0
+ self.lower_radius1 = 90
+ self.upper_radius1 = 90
+
+ # Second volume is a cylinder.
+ self.lower_radius2 = 100
+ self.upper_radius2 = 100
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(1.1 * volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 5:
+ # First volume is a cylinder.
+ self.height1 = 200.0
+ self.lower_radius1 = 90
+ self.upper_radius1 = 90
+
+ # Second volume is a cylinder.
+ self.lower_radius2 = 100
+ self.upper_radius2 = 100
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(0.9 * volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 6:
+ # First volume is a cylinder.
+ self.height1 = 180.0
+ self.lower_radius1 = 87
+ self.upper_radius1 = 87
+
+ # Second volume is an inverted cone.
+ self.lower_radius2 = 110
+ self.upper_radius2 = 55
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 7:
+ # First volume is a cylinder.
+ self.height1 = 180.0
+ self.lower_radius1 = 87
+ self.upper_radius1 = 87
+
+ # Second volume is an inverted cone.
+ self.lower_radius2 = 110
+ self.upper_radius2 = 55
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(1.1 * volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 8:
+ # First volume is a cylinder.
+ self.height1 = 180.0
+ self.lower_radius1 = 87
+ self.upper_radius1 = 87
+
+ # Second volume is an inverted cone.
+ self.lower_radius2 = 110
+ self.upper_radius2 = 55
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(0.9 * volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 9:
+ # First volume is a cone.
+ self.height1 = 120.0
+ self.lower_radius1 = 45
+ self.upper_radius1 = 70
+
+ # Second volume is an inverted cone.
+ self.lower_radius2 = 60
+ self.upper_radius2 = 25
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 10:
+ # First volume is a cone.
+ self.height1 = 120.0
+ self.lower_radius1 = 45
+ self.upper_radius1 = 70
+
+ # Second volume is an inverted cone.
+ self.lower_radius2 = 60
+ self.upper_radius2 = 25
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(1.1* volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
+ elif problem_number == 11:
+ # First volume is a cone.
+ self.height1 = 120.0
+ self.lower_radius1 = 45
+ self.upper_radius1 = 70
+
+ # Second volume is an inverted cone.
+ self.lower_radius2 = 60
+ self.upper_radius2 = 25
+
+ volume1 = self.calculate_volume(self.height1, self.lower_radius1, self.upper_radius1)
+ self.height2 = self.calculate_height_for_equal_volume(0.85 * volume1, self.lower_radius2, self.upper_radius2)
+ volume2 = self.calculate_volume(self.height2, self.lower_radius2, self.upper_radius2)
+
# Initial positions for the shapes.
left_position = Vector(600, 500 - self.height1/2)
right_position = Vector(900, 500 - self.height2/2)