Hi all!
I have a surface and multiple points that goes down by a move function.
I want to stop them whenever the subtraction of the last two points reaches a value of 0.005.
How to stop the move and update each of the points in the list individually?
Code here
import Rhino.Geometry as rg
import ghpythonlib.treehelpers as th
import random
# CREATING A CLASS CALLED PARTICLE
class Particle:
def __init__(self, point, surface):
self.pt = point
self.srf = surface
self.vec = rg.Vector3d.Unset
self.plane = rg.Plane.Unset
# A LIST CALLED HISTORY (starts with point self.pt)
self.history = [self.pt]
# A METHOD CALLED UPDATE (updates the position of the particle)
def update(self):
self.move()
self.history.append(self.pt)
# A NEW METHOD CALLED MOVE
def move(self):
#unpacking the returning values from the function
success, U, V = self.srf.ClosestPoint(self.pt)
if success:
self.pt = self.srf.PointAt(U, V)
self.plane = self.srf.FrameAt(U, V)[1]
worldZ = rg.Vector3d.ZAxis
localZ = self.plane.ZAxis
vec1 = rg.Vector3d.CrossProduct( worldZ, localZ)
vec2 = rg.Vector3d.CrossProduct( vec1, localZ)
self.vec = vec2
self.vec.Unitize()
self.vec *= step
self.pt += self.vec
allParticles = []
for pt in pts:
p = Particle(pt, srf)
allParticles.append(p)
allHistory = []
for i in range(count):
for p in allParticles:
p.update()
allHistory.append(p.history)
a = th.list_to_tree(allHistory)
lastpointsZ = []
for p in allParticles:
lastpointsZ.append(p.history[-1].Z)
secondlastpointsZ = []
for p in allParticles:
secondlastpointsZ.append(p.history[-2].Z)
# SUBTRACT THE SECOND TO LAST POINT FROM THE LAST POINT
resultingZ = []
for i in range(len(lastpointsZ)):
resultingZ.append(abs(secondlastpointsZ[i]) - abs(lastpointsZ[i]))
print lastpointsZ
print secondlastpointsZ
print resultingZ
Thanks!
