add purge

mesh
Theophile Terraz 2023-07-06 11:33:59 +02:00
parent 4935069864
commit fa35d49a42
2 changed files with 31 additions and 1 deletions

View File

@ -278,11 +278,12 @@ class ProfileXYZ(Profile):
x = self.x()
y = self.y()
z = self.z()
for i in len(self.points)-1:
for i in range(len(self.points)-1):
dx = x[i+1] - x[i]
dy = y[i+1] - y[i]
dz = z[i+1] - z[i]
l.append( np.sqrt(dx*dx + dy*dy + dz*dz) )
return l
@ -294,5 +295,25 @@ class ProfileXYZ(Profile):
for i in l:
lc = lc + i
lcum.append(lc)
return lcum
@timer
def purge(self, np) -> list:
points = self.points
if (self.number_points <= np): return points
while len(points) > np:
x1 = [point.x() for point in points]
y1 = [point.y() for point in points]
z1 = [point.z() for point in points]
l = [(x*x+y*y+z*z) for (x,y,z) in zip(x1,y1,z1)]
l2 = [(x + y) for (x, y) in zip(l[:-1], l[1:])]
imin = np.argmin(l2)+1
points.pop(imin)
return points

View File

@ -704,3 +704,12 @@ class Reach:
if n <= npoint_max: # we add the missing points at the end of the profile
for k in range(n,npoints_max): new_profiles[isect].add_point(new_profiles[isect].points[-1])
@timer
def purge(self, np: int) -> list:
profiles = []
for profile in self.profiles():
points = profile.purge(np)
profiles.append(ProfileXYZ())
profiles[-1].import_points(points)
return profiles