Hi, i have an array of Vector3 points. is there a good way to find the center? thanks a lot!
Cheers!
Hi, i have an array of Vector3 points. is there a good way to find the center? thanks a lot!
Cheers!
Find the average of the points.
hi, i just tried that, but when there are lets say 5 points on one side an one on the other, the average will be torwards the 5 points, not in the geometrical middle.
Any idea how to get this done?
Thanks!!
Depends on your definition of center. The one I gave is the center of mass where points have unit mass, ie the balance point.
What do you mean by center?
Find the max and min of all the vectors, then add the two of them together and multiply by 0.5.
const min = new vec3(Number.Infinity...)
const max = new vec3(-Number.Infinity...)
vectors.forEach(vec=>{
min.x = Math.min(min.x, vec.x)
min.y = Math.min(min.y, vec.y)
min.x = ...
max.x = Math.max(max.x, vec.x)
max.y = ...
max.z = ...
})
const result = max.add(min).scale(0.5)
I think, just rolled out of bed and have not had coffee but off the top of my head I think this is what you want.
Hello just checking in, was your question answered? @pcace
yes thanks for the reminder!