Skip to content

Instantly share code, notes, and snippets.

@csaez
Last active May 20, 2019 08:27
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 csaez/df14e02b14537c55ea56828b68212166 to your computer and use it in GitHub Desktop.
Save csaez/df14e02b14537c55ea56828b68212166 to your computer and use it in GitHub Desktop.
import unittest
def ikePoleVector(root, mid, end):
result = []
for i in range(len(root)):
v1 = end[i] - root[i]
midV1 = v1 * 0.5
v2 = end[i] - midV1
v3 = mid[i] - v2
vf = mid[i] + v3
result.append(vf)
return result
def normalizedPoleVector(root, mid, end):
indices = range(len(root))
a = [mid[i] - root[i] for i in indices]
c = [end[i] - root[i] for i in indices]
dotAC = sum([a[i] * c[i] for i in indices])
dotCC = sum([c[i] * c[i] for i in indices])
ratio = dotAC / dotCC
result = []
for i in indices:
ref = c[i] * ratio
v2 = root[i] + ref
v3 = mid[i] - v2
vf = mid[i] + v3
result.append(vf)
return result
class PoleVectorCase(unittest.TestCase):
def test_ike_regular_sides(self):
self.assertEqual(ikePoleVector([0.0, 0.0], [1.0, -1.0], [2.0, 0.0]), [1.0, -2.0])
def test_ike_irregular_sides(self):
self.assertEqual(ikePoleVector([0.0, 0.0], [0.1, -1.0], [2.0, 0.0]), [0.1, -2.0]) # fails
def test_norm_regular_sides(self):
self.assertEqual(normalizedPoleVector([0.0, 0.0], [1.0, -1.0], [2.0, 0.0]), [1.0, -2.0])
def test_norm_irregular_sides(self):
self.assertEqual(normalizedPoleVector([0.0, 0.0], [0.1, -1.0], [2.0, 0.0]), [0.1, -2.0])
if __name__ == "__main__":
unittest.main(exit=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment