- Home /
How do I mix two values as if they were fluids?
Hello. In my scene I have a fluid object, which has certain properties, such as volume, density, temperature and so on. I want it so that if while holding down a certain key, another kind of fluid is gradually added to the one already present. I have the volume figured out, since it is simply a matter of increasing the value multiplied by Time.deltaTime, however I cannot figure out how to mix things such as temperature and density. My theory is, if I have a fluid which is 20° and I add to it another fluid of the same volume which is 40°, the temperature should be 30°, since it is the average of the two fluids. However, since I want it to change gradually as the user holds the key down and pours more liquid, I don't have two specific volumes that I can average out. I would like it so that as I pour more of a fluid of a certain temperature in another one, the resulting temperature gradually averages out. How do I mix the two fluids in a realistic manner?
This is the code I currenly use to increase the fluid's volume.
function AddFluid(addSpeed:float) {
addedFluid = new Fluid(1,0,0); //this is a custom class with the fluid's properties
currentFluid.volu += addedFluid.volu * Time.deltaTime * addSpeed; }
I hope I have been sufficiently clear. Thanks
This is not really a Unity question. If you google for "calculating the temperature of a mixture," You will find lots of hits. Assu$$anonymous$$g both liquids have the same heat capacity, you can use the equation by $$anonymous$$ybert most of the way down this page:
http://www.scienceforums.net/topic/16788-calculating-mixed-water-temperature/
Note that since in Unity you will be poring over time, after each frame of calculating, you will end up with a new volume and temperature for fluid 'A', which will then be used in the next frame of calculation. So the temperature of 'A' will come up gradually, and the volume will increase gradually.
Answer by Bunny83 · Aug 25, 2013 at 01:23 AM
I'm actually shocked that the wikipedia pages in english are horrible or even not existant.
What you need to know are:
The specific heat capacity "c" of both liquids. If you mix the same liquid this can be ignored.
The temperature "T" of both liquids.
The mass "m" of both liquids.
If you only have the volume you additionally neeed the density of both liquids to calculate the mass out of the volume.
To calulate the energy in a material there's this forumla:
Q = c * m * T
where T is the absolute temperature (kelvin scale)
To calculate the mixture temperature of two materials you use this one:
Tmix = (c1*m1*T1 + c2*m2*T2) / (c1*m1 + c2*m2)
Keep in mind if you're mixing the same materials you can simply omit c and can even use the volume instead of the mass. In this special case you could use:
Tmix = (V1*T2 + V2*T2) / (V1+V2)
To calculate the temperature while the two fluids are mixing you just have to use the current values. So each time you calculate the new volume (V1+V2) you would also calculate the new temperature (Tmix)
This is btw the Richmannsche Mischungsregel (sorry but i only found the german wiki page :| ).
Anyway what you actually want can't be done in a "realistic manner" since mixing two fluids takes time until you actually have an average temperature. You don't get that immediately. The temerature has to spread out in the volume.
Since you didn't tell us for what putpose you need this, it makes not much sense to go any further here.
Just as side note: the density will never really "mix" since if the fluids come to rest the would be seperated due to gravity if they have different dendities.
Answer by trs9556 · Aug 24, 2013 at 11:28 PM
You could have a method to get current temperature and one to set current temperature (and density). From there you can get the temp of fluid one and the temp of fluid two, do whatever math you wish to do (averaging you mentioned) and then set the value to the fluid.