Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tools.py
diff options
context:
space:
mode:
authorAlex <alex@Tiresias.(none)>2008-07-02 16:47:40 (GMT)
committer Alex <alex@Tiresias.(none)>2008-07-02 16:47:40 (GMT)
commit1763748155fdc702e9cb9c2e2b0ef01a323af7a9 (patch)
tree4b96638e06c69d57fd7749fa52d55ba5e8812df8 /tools.py
parent29b347f421e890eb299bc888f96a270fb109a2e5 (diff)
Added comments to tools.py
Diffstat (limited to 'tools.py')
-rw-r--r--tools.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools.py b/tools.py
new file mode 100644
index 0000000..87dd4f7
--- /dev/null
+++ b/tools.py
@@ -0,0 +1,22 @@
+#==================================================================
+# Physics.activity
+# Helper classes and functions
+# By Alex Levenson
+#==================================================================
+import math
+# distance calculator, pt1 and pt2 are ordred pairs
+def distance(pt1, pt2):
+ return math.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] -pt2[1]) ** 2)
+
+# returns the angle between the line segment from pt1 --> pt2 and the x axis, from -pi to pi
+def getAngle(pt1,pt2):
+ xcomp = pt2[0] - pt1[0]
+ ycomp = pt1[1] - pt2[1]
+ return math.atan2(ycomp,xcomp)
+
+# returns a list of ordered pairs that describe an equilteral triangle around the segment from pt1 --> pt2
+def constructTriangleFromLine(p1,p2):
+ halfHeightVector = (0.57735*(p2[1] - p1[1]), 0.57735*(p2[0] - p1[0]))
+ p3 = (p1[0] + halfHeightVector[0], p1[1] - halfHeightVector[1])
+ p4 = (p1[0] - halfHeightVector[0], p1[1] + halfHeightVector[1])
+ return [p2,p3,p4]