3 ms·
That's clever! I updated the code and it seems to work for the several times I refreshed now. Thanks! This was the final cost function that worked: let encl
by arnioxux 9y ago
That's clever! I updated the code and it seems to work for the several times I refreshed now. Thanks!
This was the final cost function that worked:
let encloseCost = 0;
let farthestPointCost = 0;
for (let i = 0; i < B.length; i++) {
const b = B[i];
const dx = b.x - a.x;
const dy = b.y - a.y;
encloseCost += Math.max(
0,
-a.r + (b.r + Math.sqrt(dx * dx + dy * dy))
);
farthestPointCost = Math.max(
farthestPointCost,
b.r + Math.sqrt(dx * dx + dy * dy)
);
}
const radiusCost = Math.abs(a.r);
const totalCost = encloseCost + farthestPointCost + radiusCost;