PDA

View Full Version : Bounding Box w/ Coffee


johann.dugge
08-25-2006, 01:03 PM
Is there a faster way to get the boundingbox of a polyobject then evaluating all points individually? Here's the code I wrote, but it is way too slow on large scenes:


GetBoundingMax(obj)
{
var ptCount = obj->GetPointCount();
var ptArray = (obj->GetPoints());
var maxPoint = ptArray[0];

var i;
for (i = 1; i < ptCount; i++)
{
if (ptArray[i].x > maxPoint.x) {
maxPoint.x = ptArray[i].x; }
if (ptArray[i].y > maxPoint.y) {
maxPoint.y = ptArray[i].y; }
if (ptArray[i].z > maxPoint.z) {
maxPoint.z = ptArray[i].z; }
}
return maxPoint;
}


Cheers!

johann.dugge
08-25-2006, 01:46 PM
uh, nevermind. Somewhere in my other code I compared two vectors for equality, but due to rounding errors they would never be the same! So now I changed the code to accomodate for a small percentage error, et voilą: it works fine.

Kuroyume0161
08-26-2006, 06:15 AM
Not even rounding errors - floating point values need to be compared for equality on a significance basis - using an epsilon. The C++ SDK has a VectorEqual() method that compares with an epsilon value. COFFEE doesn't, but the compare is rather simple:

var VectorEqual(var v1, var v2, var epsilon)
{
// Not Equivalent = FALSE
// Equivalent = TRUE
return (Abs(v1.x-v2.x)<epsilon && Abs(v1.y-v2.y)<epsilon && Abs(v1.z-v2.z)<epsilon);
}

A good value for epsilon depends on the circumstances, but usually something like 0.001 (for instance) is a good epsilon value.

johann.dugge
08-26-2006, 09:10 AM
Thanks Robert for that! I think your way of testing is faster than mine. I used vlen() to do the percentage error thing. But that probably is more expensive and less accurate.

BTW, there's an error in my code above, I'll fix it right now.

CGTalk Moderation
08-26-2006, 09:10 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.