Skip to content

Instantly share code, notes, and snippets.

@mattslay
Last active September 7, 2016 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattslay/11ad3bc5113e6699b4525baedb327afb to your computer and use it in GitHub Desktop.
Save mattslay/11ad3bc5113e6699b4525baedb327afb to your computer and use it in GitHub Desktop.
import math
class cylinder(object):
feature_type = "cylinder"
def __init__(self, diameter, length):
self.diameter = diameter
self.length = length
self._start_z = 0.00
def volume(self):
area = ((self.diameter / 2.0) ** 2) * math.pi
volume = area * self.length
return volume
def end_z(self):
return self._start_z + self.length
class shaft(object):
def __init__(self):
self.features = []
def volume(self):
volume = 0.00
for feature in self.features:
volume = volume + feature.volume()
return volume
def length(self):
length = 0
for feature in self.features:
length = length + feature.length
return length
def add_feature(self, feature):
feature._start_z = self.length
self.features.append(feature)
#-- Create some cylinder objects
c1 = cylinder(10.25, 1.25)
c2 = cylinder(8.25, 4.375)
s = shaft() #-- Create a new Shaft Objects
#-- Add cylinder objects to Shaft
s.add_feature(c1)
s.add_feature(c2)
print("Cylinder 1 Volume = %f Start_z = %f" % (c1.volume(), c1._start_z()))
print("Cylinder 2 Volume = %f Start_z = %f" % (c2.volume(), c2._start_z()))
#-- Display some info about the Shaft, which are derived from the Cylinder objects
#-- of which it is made of.
print("\nTotal Volume: %f cubic units" % s.volume())
print("\nOverall Length: %s" % s.length())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment