alice_v3.0.4
alice_v3.0.4

Reputation: 95

How to approximate a 3D shape to a grid?

Given a 3D object, how do I convert it into an approximated shape in which all the sides of the object are parallel to either of the co-ordinate planes, and all the vertices have integer co-ordinates? For example, a sphere with center at origin and a radius of 1.5 will be approximated to a cube with center at origin and side length of 2. For another example, the line given by x = y = 0.5 will have an approximated shape as a rectangular parallelepiped with infinite length, and width and breadth as 1, and positioned such that one of its edge is along z-axis, while all the faces are along or parallel to either of x-z or y-z co-ordinate planes.

I am working with finite objects only, the above example is only meant to explain my needs. I want an algorithm which can do this for me for any shape.

Upvotes: 0

Views: 220

Answers (1)

MBo
MBo

Reputation: 80187

In general case you need to determine maximum and minimum shape coordinates along every axis and define minimum axis aligned integer bounding box with values rounded to larger (using Ceil) for max and rounded to smaller (using Floor) for min coordinates. For example:

XMin_Box = Floor(XMin_Shape)
XMax_Box = Ceil(XMax_Shape)

Edit:

If you need to approximate a shape with more precision, consider some kind of voxelization (3d analog of 2d rasterization)

Upvotes: 2

Related Questions