diff --git a/map.py b/map.py index b8ce5cc..4adee05 100644 --- a/map.py +++ b/map.py @@ -15,13 +15,17 @@ class Triangle: self.v1 = v1 self.v2 = v2 self.v3 = v3 + # Sort triangle vertices so that so that the normal points "outward" + if np.dot(self.v1, np.cross(self.v2 - self.v1, self.v3 - self.v1)) < 0: + self.v3, self.v2 = self.v2, self.v3 # Edges of the origin vertex and their L2 norms - self.e1 = v2 - v1 - self.e2 = v3 - v1 + self.e1 = self.v2 - self.v1 + self.e2 = self.v3 - self.v1 self.e1n = np.linalg.norm(self.e1) self.e2n = np.linalg.norm(self.e2) # Normal vector of the triangle's plane self.n = np.cross(self.e1 / self.e1n, self.e2 / self.e2n) + self.n = self.n / np.linalg.norm(self.n) # The vertex coordinates in plane coordinates self.v1p = self.plane_coords(self.v1) self.v2p = self.plane_coords(self.v2)