mirror of https://gitlab.com/pamhyr/pamhyr2
work on purge
parent
9f0caaaa69
commit
e1880c6549
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from math import dist
|
||||
from math import dist, sqrt, acos
|
||||
import numpy as np
|
||||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
|
|
@ -212,3 +212,38 @@ class PointXYZ(Point, SQLSubModel):
|
|||
Euclidean distance between the two points
|
||||
"""
|
||||
return dist((p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z))
|
||||
|
||||
@staticmethod
|
||||
def angle(p1, p2, p3):
|
||||
"""angle p1 p2 p3.
|
||||
|
||||
Args:
|
||||
p1: A XYZ Point
|
||||
p2: A XYZ Point
|
||||
p3: A XYZ Point
|
||||
|
||||
Returns:
|
||||
angle p1 p2 p3
|
||||
"""
|
||||
a = PointXYZ.distance(p1, p2)
|
||||
b = PointXYZ.distance(p2, p3)
|
||||
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.
|
||||
|
||||
Args:
|
||||
p1: A XYZ Point
|
||||
p2: A XYZ Point
|
||||
p3: A XYZ Point
|
||||
|
||||
Returns:
|
||||
triangle height starting at p2
|
||||
"""
|
||||
a = PointXYZ.distance(p1, p2)
|
||||
b = PointXYZ.distance(p2, p3)
|
||||
c = PointXYZ.distance(p1, p3)
|
||||
h2 = a**2 - ((c**2 - b**2 + a**2) / 2*c)**2
|
||||
return sqrt(h2)
|
||||
|
|
|
|||
|
|
@ -450,6 +450,20 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
|
||||
return points
|
||||
|
||||
@timer
|
||||
def purge2(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.angle(points(i),points(i+1),points(i+2)))
|
||||
imax = np.argmax(l2)+1
|
||||
points.pop(imax)
|
||||
|
||||
return points
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -802,7 +802,7 @@ class Reach(SQLSubModel):
|
|||
def purge(self, np: int) -> list:
|
||||
profiles = []
|
||||
for profile in self.profiles():
|
||||
points = profile.purge(np)
|
||||
points = profile.purge2(np)
|
||||
profiles.append(ProfileXYZ())
|
||||
profiles[-1].import_points(points)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue