Last active
May 20, 2019 08:27
-
-
Save csaez/df14e02b14537c55ea56828b68212166 to your computer and use it in GitHub Desktop.
Commenting on https://twitter.com/AlbertoGzG/status/937262615457345539
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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