Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
 summaryrefslogtreecommitdiffstats log msg author committer range
path: root/helpers.py
diff options
 context: 12345678910152025303540 space: includeignore mode: unifiedssdiff
author committer Alex 2008-07-08 21:11:48 (GMT) Alex 2008-07-08 21:11:48 (GMT) d610e626c0f6085fa27de62a3113ef722a310f85 (patch) 8af609d2aceb9abca5f302b7bfdd7b3057445885 /helpers.py e2e93519e067f526ff285db53921e900f259ad72 (diff)
Total Reorganization! Now a proper activity (I hope)
Diffstat (limited to 'helpers.py')
-rw-r--r--helpers.py22
1 files changed, 22 insertions, 0 deletions
 diff --git a/helpers.py b/helpers.pynew file mode 100644index 0000000..87dd4f7--- /dev/null+++ b/helpers.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]