Followers 0

# C# Best way to determine the # of times a single product could fit within a

## 4 posts in this topic

Math time!

So I'm working on a project where you have those plastic adjustable compartment boxes, and you want to fill one of those compartments with a certain product. I want to figure out how many can fit instead said box.

At the most basic level, I could do.

`		public static int VolCalc(int mLength, int mWidth, int mHeight, out int mVol)		{			// Solve for product and compartment volume.			mVol = mLength * mWidth * mHeight;			return mVol;		}		public static int TotalCalc(int mPVol, int mBVol, out int mTot)		{			// Solve for # of times a product can fill the box.			var pMultiply = 0;			for (mTot = 0; pMultiply <= mBVol;)			{				mTot++;				pMultiply = mPVol * mTot;			}			// Since I'm using integers, remove the last one to account for <=.			mTot -= 1;			return mTot;		}[/CODE]`

Would you consider this the best way to approach this problem?

##### Share on other sites

Math time!

So I'm working on a project where you have those plastic adjustable compartment boxes, and you want to fill one of those compartments with a certain product. I want to figure out how many can fit instead said box.

At the most basic level, I could do.

`		public static int AreaCalc(int mLength, int mWidth, int mHeight, out int mArea)		{			// Solve for product and compartment area.			mArea = mLength + mWidth + mHeight;			return mArea;		}		public static int TotalCalc(int mPArea, int mBArea, out int mTot)		{			// Solve for # of times a product can fill the box.			var pMultiply = 0;			for (mTot = 0; pMultiply <= mBArea;)			{				mTot++;				pMultiply = mPArea * mTot;			}			// Since I'm using integers, remove the last one to account for <=.			mTot -= 1;			return mTot;		}[/CODE]`

Would you consider this the best way to approach this problem?

The first function would be volume for a start, and it would be the product (multiply), not an addition.

Then just divide the total volume of the room, by the smaller boxes volume.

Room is say 4 * 4 * 4 = 64 squares in volume.

The box is 2 * 2 * 2 = 8 squares in volume

64/8 = 8 boxes in total.

The real issue is dealing with partial boxes, so you might have to use some MOD in there. The calc would try to stretch or squeeze boxes, so you can only deal in integer boxes in each direction.

##### Share on other sites

Oh yeah volume duh 3d.

##### Share on other sites

The first function would be volume for a start, and it would be the product (multiply), not an addition.

Then just divide the total volume of the room, by the smaller boxes volume.

Room is say 4 * 4 * 4 = 64 squares in volume.

The box is 2 * 2 * 2 = 8 squares in volume

64/8 = 8 boxes in total.

The real issue is dealing with partial boxes, so you might have to use some MOD in there. The calc would try to stretch or squeeze boxes, so you can only deal in integer boxes in each direction.

I'll look into the changes.

No.

## Create an account

Register a new account