diff --git a/src/Model/Geometry/PointXYZ.py b/src/Model/Geometry/PointXYZ.py index 22d2f674..95f44219 100644 --- a/src/Model/Geometry/PointXYZ.py +++ b/src/Model/Geometry/PointXYZ.py @@ -230,6 +230,7 @@ class PointXYZ(Point, SQLSubModel): c = PointXYZ.distance(p1, p3) return acos((a**2 + b**2 - c**2) / (2 * a * b)) + @staticmethod def triangle_height(p1, p2, p3): """triangle p1 p2 p3 height starting at p2. @@ -247,3 +248,19 @@ class PointXYZ(Point, SQLSubModel): c = PointXYZ.distance(p1, p3) h2 = a**2 - ((c**2 - b**2 + a**2) / 2*c)**2 return sqrt(h2) + + @staticmethod + def triangle_area(p1, p2, p3): + """triangle p1 p2 p3 area. + + Args: + p1: A XYZ Point + p2: A XYZ Point + p3: A XYZ Point + + Returns: + triangle height starting at p2 + """ + h = PointXYZ.triangle_height(p1, p2, p3) + d = PointXYZ.distance(p1, p3) + return h*d/2 diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py index c5066ead..da1ebdfb 100644 --- a/src/Model/Geometry/ProfileXYZ.py +++ b/src/Model/Geometry/ProfileXYZ.py @@ -435,7 +435,7 @@ class ProfileXYZ(Profile, SQLSubModel): return lcum @timer - def purge(self, np) -> list: + def purge1(self, np) -> list: points = self.points if (self.number_points <= np): return points @@ -464,6 +464,20 @@ class ProfileXYZ(Profile, SQLSubModel): return points + @timer + def purge3(self, np) -> list: + + points = self.points + if (self.number_points <= np): return points + while len(points) > np: + l2 = [] + for i in range(len(points)-2) + l2.append(PointXYZ.triangle_area(points(i),points(i+1),points(i+2))) + imin = np.argmin(l2)+1 + points.pop(imin) + + return points +