Scripting Repeat

whaynes shared this question 3 years ago
Answered

Is there a more compact way to write this for a long list. I tried to make it work using repeat, but was unsuccessful.


SetValue(C,If[Distance[C,list1(1)] < .05,list1(1),C])

SetValue(C,If[Distance[C,list1(2)] < .05,list1(2),C])

SetValue(C,If[Distance[C,list1(3)] < .05,list1(3),C])

many more similar...


I'm trying to snap point C to any of a large number of points in the list.

Comments (2)

photo
1

for many in 1 command:


  1. SetValue[C, If[Distance[C,ClosestPoint[C,list1]] <0.05, ClosestPoint[C,list1], C]]

.

photo
1

Very cool! I was not aware of the ClosestPoint[ ] function.

© 2020 International GeoGebra Institute