3D Volumetrics
Page 1 of 111 Replies  904 Views  Last Post: 11 January 2013  01:20 AM
#1
3D Volumetrics
Posted 28 December 2012  04:41 PM
Replies To: 3D Volumetrics
#2
Re: 3D Volumetrics
Posted 28 December 2012  04:48 PM
#3
Re: 3D Volumetrics
Posted 28 December 2012  05:02 PM
After looking at this, I realized that it is more complex than I am needing. I am looking for a simple calculator, and I really do not need the visual aspect of it. I would simply like to put in a series of coordinates and obtain a volume. Perhaps examining this will help me along.
#4
Re: 3D Volumetrics
Posted 28 December 2012  06:22 PM
#5
Re: 3D Volumetrics
Posted 28 December 2012  08:40 PM
Are you looking to find the volume under a plane?
http://www.math24.ne...integrals.html
This post has been edited by BlueMelon: 28 December 2012  08:42 PM
#6
Re: 3D Volumetrics
Posted 29 December 2012  07:50 AM
Quote
2. Divide your box into smaller boxes. If you are working in 2D, cut it along the x and y axes giving 4 smaller boxes. If you are in 3D then cut along the z axis too giving 8 smaller boxes.
3. Take each box in turn. A box will fall into one of three categories:
3A. It lies entirely outside your data set. Subtract its volume from your initial estimate and discard the box. You don't need it any more.
3B. It lies entirely inside your data set. Discard the box so you don't keep dividing it but do not adjust your initial estimate.
3C. Part of the box lies inside your data set and part lies outside. Add the box to a list that need to be further divided. Don't adjust the estimated volume yet.
4. Run through the list of boxes that need to be divided (a queue is a nice data structure for this) until the estimated volume is within an acceptable error distance of the actual value. How do you know this? It's when the total volumes of the boxes in the queue is less than the error value. (This sounds imprecise but you can make the error value as small as you wish)
You can make the algorithm simpler by starting with the queue and adding the first box to it. The tricky part is working out if a box is inside/outside or partially inside your data set. I'll leave that to you just now. Come back if you are stuck!
#7
Re: 3D Volumetrics
Posted 29 December 2012  08:02 AM
#8
Re: 3D Volumetrics
Posted 29 December 2012  08:15 AM
(If the number of subdivision > infinity, it should give the integral)
#9
Re: 3D Volumetrics
Posted 29 December 2012  04:18 PM
#10
Re: 3D Volumetrics
Posted 30 December 2012  09:17 AM
Thinking about it, another option is triangulation. You pick any four points to start with. They make a pyramid shape, the volume of which you can calculate easily. You then loop over each of the remaining points in turn. With each, you find the three closest points that have already been used, create a pyramid and add the volume to the running total. One thing to watch out for is points being inside existing pyramids. You want to ignore those points or you will end up counting sections of the area twice. Like Riemann sums, you will also have to split your shape into convex sections.
#11
Re: 3D Volumetrics
Posted 08 January 2013  03:35 PM
#12
Re: 3D Volumetrics
Posted 11 January 2013  01:20 AM
Sorry, I saw the post you made in your thread but this week has been crazy with deadlines for me. A Point3D class is pretty simple to make. All you need is a constructor that takes x, y and z and three getters along the lines of:
public double getX() { return x; }
A toString() might be useful for debugging too.
The cube is slightly more involved but the key method is:
public boolean contains(Point3D p) { // your code here }
It should obviously return true if the point lies inside the box, false otherwise.
Another key method would be one that splits it into smaller boxes. Something like this (although you could use an array instead of a list)
public List<Cube> split() { List<Cube> result = new ArrayList<>(); // Your code here return result; }
I've not talked about the internal representation of the box because there are a lot of options, all of which are fine. A reasonable one would be storing a Point3D for the (minX, minY, minZ) (let's call it origin) and a double for the length of a side (called length). This is the minimum needed to define a cube. You'll need more to fill in the gaps in the methods above but that should be done through methods like these (notice that they are all private):
private boolean containsX(Point3D p) { double x = p.getX(); return (x >= minX()) && (x < maxX()); } private double minX() { return origin.getX(); } private double maxX() { return minX() + length; }
Your containsY() and containsZ() methods will look very similar! Could that be an opportunity to eliminate duplicate code?
This should be enough for you to make a good start. The tricky part is when you have boxes that contain no points. The computer has to decide if the box is inside or outside the model. See if you can find a solution and come back for help if you need it.
I'm going to post this on your thread. It's the best place for discussions since this post might help someone else in the future and it gives others a chance to chip in with something I haven't thought of.
