src/geometry.cpp

changeset 223
ce81db996275
parent 206
654661eab7f3
child 250
2837b549e616
--- a/src/geometry.cpp	Tue Jun 14 23:04:49 2022 +0300
+++ b/src/geometry.cpp	Wed Jun 15 12:17:29 2022 +0300
@@ -199,6 +199,22 @@
 	};
 }
 
+bool isConvex(const Quadrilateral& quad)
+{
+	glm::vec3 crosses[4] = {
+		glm::cross(quad.p4 - quad.p1, quad.p2 - quad.p1),
+		glm::cross(quad.p1 - quad.p2, quad.p3 - quad.p2),
+		glm::cross(quad.p2 - quad.p3, quad.p4 - quad.p3),
+		glm::cross(quad.p3 - quad.p4, quad.p1 - quad.p4),
+	};
+	return not std::any_of(
+		&crosses[1],
+		&crosses[4],
+		[&crosses](const glm::vec3& vector) {
+			return glm::dot(crosses[0], vector) < 1e-6;
+		});
+}
+
 bool isConvex(const std::vector<glm::vec3>& polygon)
 {
 	const int n = polygon.size();

mercurial