Hoi Folks,
Im building a conform script and i struggle a lot how to get the three
nearest vertices to a given vertice in one iteration. I coded a little
thing to get it for two but Im hardly confused how to do it. Any help
would be really nice . Greetings EliderDeli
local oldDistance = 1e9
local oldDistance2 = 1e9
local oldDistance3 = 1e9
indexNearestVertice = undefined
first = 0
second = 0
third = 0
myList = refObj.selectedVerts
for i=1 to myList.count by 1 do
(
distanceO = calculatdistance myList[i].pos SelectedVerticeID.pos
if (distanceO < oldDistance) then
(
second = first
first = myList[i]
oldDistance = distanceO
)
if (distanceO < oldDistance2 && distanceO != oldDistance) then second = myList[i]
)
Replies
- When you just want to compare the distances between themselves (like finding the farthest or closest distances), you can optimise by comparing the squared distances (which uses simpler math) instead of the actual distances (which needs square root).
(This happens to work because if x > y, then x² > y²)
- Use a list to keep track of the three closest distances, and each time you find a closer distance, advance all entries on the list so it always keeps the closest 3 distances that you found.