Condensed transform_to_xy

Mon, 22 Jan 2018 01:01:10 +0200

author
Santeri Piippo
date
Mon, 22 Jan 2018 01:01:10 +0200
changeset 15
45b3aeb25003
parent 14
d383f319f35b
child 16
09cc89622262

Condensed transform_to_xy

geometry.py file | annotate | diff | comparison | revisions
--- a/geometry.py	Mon Jan 22 12:22:01 2018 +0200
+++ b/geometry.py	Mon Jan 22 01:01:10 2018 +0200
@@ -371,17 +371,15 @@
     v1, v2, v3 = polygon.vertices[:3]
     a, b = v3 - v2, v1 - v2
     normal = cross_product(a, b).normalized()
-    v = cross_product(normal, Vector(0, 0, 1))
-    cosine = dot_product(normal, Vector(0, 0, 1))
     v_matrix = Matrix3x3([
-        0, -v.z, v.y,
-        v.z, 0, -v.x,
-        -v.y, v.x, 0,
+        0, 0, -normal.x,
+        0, 0, -normal.y,
+        normal.x, normal.y, 0,
     ])
     try:
         rotation_matrix = Matrix3x3()
         rotation_matrix += v_matrix
-        rotation_matrix += (v_matrix @ v_matrix) * (1 / (1 + cosine))
+        rotation_matrix += (v_matrix @ v_matrix) * (1 / (1 + normal.z))
     except ZeroDivisionError:
         rotation_matrix = Matrix3x3()
     full_matrix = complete_matrix(rotation_matrix, Vertex(0, 0, 0))

mercurial