Archtic
02-12-2008, 11:45 PM
Hi Everybody,
I've been trying to come up with a script that takes an input spline, and rearranges the knots according to their distance from each other, with the first knot being fixed, then the next nearest knot, then the next nearest to that, etc.......
So far I've come up with this:
(
originalpointarray = for i = 1 to (numknots $ 1) collect (getknotpoint $ 1 i)
pointarray = originalpointarray
newpoints = #()
newpoint = [0,0,0]
indexcheck = 0
for i = 1 to originalpointarray.count do
(
checkdist = 9999.0
--if pointarray.count == 1 do continue
for j = 1 to pointarray.count do
(
if pointarray[i] == pointarray[j] do continue
newdist = distance pointarray[i] pointarray[j]
if newdist <= checkdist then
(
checkdist = newdist
newpoint = pointarray[j]
indexcheck = j
)
)
append newpoints newpoint
deleteitem pointarray indexcheck
)
print newpoints
)
This takes a selected spline, and tests each point against an array of the same points, identifying the closest one, then deleting that value from the array that contains the remaining points to be checked against. It finally outputs the new ordered array of knots...
But still no joy.... I have a feeling I'm missing something!
Any pointers would be greatly appreciated.
Archtic.
I've been trying to come up with a script that takes an input spline, and rearranges the knots according to their distance from each other, with the first knot being fixed, then the next nearest knot, then the next nearest to that, etc.......
So far I've come up with this:
(
originalpointarray = for i = 1 to (numknots $ 1) collect (getknotpoint $ 1 i)
pointarray = originalpointarray
newpoints = #()
newpoint = [0,0,0]
indexcheck = 0
for i = 1 to originalpointarray.count do
(
checkdist = 9999.0
--if pointarray.count == 1 do continue
for j = 1 to pointarray.count do
(
if pointarray[i] == pointarray[j] do continue
newdist = distance pointarray[i] pointarray[j]
if newdist <= checkdist then
(
checkdist = newdist
newpoint = pointarray[j]
indexcheck = j
)
)
append newpoints newpoint
deleteitem pointarray indexcheck
)
print newpoints
)
This takes a selected spline, and tests each point against an array of the same points, identifying the closest one, then deleting that value from the array that contains the remaining points to be checked against. It finally outputs the new ordered array of knots...
But still no joy.... I have a feeling I'm missing something!
Any pointers would be greatly appreciated.
Archtic.
