Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"08-14-11 - A note on convex hull simplification"

7 Comments -

1 – 7 of 7
Anonymous Anonymous said...

I have in-development CSG code that starts from planes and infers points from them. You never need to do anything other than find the intersection of three planes (and see whether another plane falls on either side of it).

IIRC, the main datatype is rationals with 128-bit numerators and denominators. The input planes have 23-bit integer normals and ~50 bit integer distance-from-integers. (The idea being that it allows you nearly float-precise plane orientations, and double-sized worlds.)

So (a) I bet if you work through the math you can do it without generic multiprecision code, and (b) if you want I can send you the current version and you can use my code, but you probably wouldn't want it.

August 15, 2011 at 2:00 PM

Anonymous Anonymous said...

Argh, I left out the main thing I wanted to say, which is that, because of the design, the precision required never grows, no matter how complex the objects. It's always just an operation on four *input* planes.

I assume for convex hull, something similar can be done where planes are defined on three input vertices, and then you're comparing a fourth input vertex.

In fact, I was inspired to do this by somebody's exact-integer convex hull patch for bullet; reading the code I realized it didn't seem that scary. http://code.google.com/p/bullet/issues/detail?id=275

August 15, 2011 at 2:02 PM

Blogger cbloom said...

Convex hull in ints is pretty easy; cblib/galaxy has done convex hull in ints forever. The only operation you need is :

"given 4 points, what's the volume"

I use 64 bit temporaries which means I get 19 bits for coordinates, which is plenty for instanced models but probably not enough if you treated your whole world as one model.

I was thinking of BSP ops like "generate the point from clipping these planes" , now generate new planes from points made from clipping; each time you do that the precision requirements grow. But I guess as long a you only use planes made from input verts that never arises.

It's not fully general BSP code though. Say for example you want to generate the portals out of the leafs (requires points generated by clipping). Then you want to do something like PVS which involves generating new planes that go through the portals - you're increasing precision. Probably if you're clever you can reformulate all queries in terms of only original planes, but it's less straightforward it seems to me.

August 15, 2011 at 4:11 PM

Anonymous Anonymous said...

Yeah, that's probably true. I guess the question is whether you can simplify directly somehow.

August 16, 2011 at 11:14 AM

Anonymous Anonymous said...

yay for textfields that don't remember previous values when you come 'back' to them. sigh.

resummarizing. "blah blah BSP isn't convex hull, ok yes, but PVS isn't BSP. And PVS only needs conservative stuff"

August 16, 2011 at 11:19 AM

Blogger cbloom said...

Can you do simple CSG with BSP's without infinite precision? eg. given two models, find the union or intersection. Certainly the naive implementation involves cutting against a plane, then cutting the results of that, etc. and each time you cut you increase the precision requirements. But maybe there's a better way?

Anyhoo.. I do imagine that you certainly could do approximate convex hull in ints, which currently I don't do nicely.

Also obviously you would really like to find the approximate hull directly, rather than finding the exact hull then simplifying.

etc. I mean really, this is not meant to be a good solution to this problem.

August 18, 2011 at 4:21 PM

Anonymous Anonymous said...

If the input to CSG is planes, then you can do it without infinite precision. Every vertex you generate from operations is always the intersection of 3 input planes. So the needed precision is finite.

The only operation you need is "point on side of plane test", where point is defined as the intersection of 3 planes. So the whole thing works out to a big 4x4 determinant or something, I forget exactly. I tweaked the input precision a bunch to try to find the sweet spot for 128-bit precision.

For BSP it's different unless the inputs are defined based on planes (e.g. if you took the output of the CSG and did BSP on it, they would be). But I'm not sure there's a good way of defining exact input to BSP--as soon as you want to have 4- or more-sided polygons, how do you define the vertices to guarantee that they're exactly planar (so that exact arithmetic can be well behaved)?

Of course you have the dual problem with planes; if you're supposed to have more than 3 planes meeting at a single vertex, they might not in exact arithmetic. For CSG this isn't a problem because a collection of half-spaces always defines a convex polyhedron (assuming it's closed at all), so even if it's not quite the polyhedron you meant it's still something.

A non-planar polygon would be a trickier starting point.

August 22, 2011 at 8:45 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.