1. Introduction
One of the most challenging tasks faced by science universities is ensuring the effective instruction and assessment of students in using laboratory equipment and conducting experiments successfully. On-site laboratory use is accompanied by serious risks, including the potential for accidents and equipment damage. These risks often limit the extent to which students can engage in hands-on practice and experimentation, thereby restricting opportunities for learning through trial and error. Additionally, distance learning universities that provide science education encounter an added difficulty: their students are rarely, if ever, physically present at laboratory facilities, making lab-based training and evaluation even more complex.
Virtual laboratories have emerged as a promising solution to complement traditional on-site lab training. These platforms allow students to gain familiarity with specialized equipment and experimental procedures in a safe and controlled environment. Within a virtual lab, users can interact with instruments and perform experiments as often as needed, free from the fear of accidents or equipment damage. Furthermore, these platforms provide a means of evaluating students’ performance. Assessment can be carried out either by a supervising human expert or through automated evaluation tools embedded within the virtual lab software.
This dual necessity and ambition have driven the Hellenic Open University (HOU) to develop Onlabs, a 3D virtual biology laboratory designed for remote training and evaluation of undergraduate and postgraduate students in the natural sciences. The fundamental idea behind Onlabs is that students can practice and refine their laboratory skills at home, using the software, before handling actual equipment in an on-site lab setting.
1.1. About Onlabs Virtual Lab
In contrast to traditional on-site training, Onlabs allows students to experiment freely with laboratory instruments and equipment in virtually unlimited ways. They can even intentionally or unintentionally misuse equipment and learn from their mistakes without real-world consequences.
Onlabs is designed to simulate the experience of a computer game, incorporating state-of-the-art 3D graphics and interactive elements. Users can navigate the environment using a mouse and keyboard, manipulate objects, turn knobs, click switches and more (
Figure 1).
Initially, Onlabs was developed using Hive3D (
https://www.eyelead.com/ accessed on 14 March 2025). However, since 2016, its development has transitioned to Unity. A variety of Onlabs versions are available on our website (
http://onlabs.eap.gr/ accessed on 14 March 2025), ranging from stable releases to research prototypes. The most recent stable version (version 2.1.2) includes two distinct simulated experimental procedures: microscoping and the preparation of a 10X TBE solution. It also features three distinct play modes: instruction, experimentation and evaluation.
In the microscoping experiment, users are required to set up a microscope, prepare a test specimen and observe it using all objective lenses of a photonic microscope. Meanwhile, in the preparation of 500 mL of a 10X TBE solution, users measure out 17.4 g of boric acid and 54 g of Trizma base on an electronic scale, dissolve these powders in water using a magnetic stirrer and then add additional water and EDTA pH 8.0 (ethylenediamine tetraacetic acid) to complete the solution.
The three play modes offer varying levels of guidance and freedom. In instruction mode, users follow voice and text prompts step by step, with the system only allowing the prescribed actions at each stage. Experimentation mode removes these restrictions, granting users full freedom to explore and perform any implemented actions. Finally, evaluation mode provides users with a numerical score reflecting how well they followed the experimental procedure and whether they successfully completed the simulation.
Onlabs version 3.0 beta introduces two updated experimental procedures that replace those in version 2.1.2. These include microscoping, as featured in previous versions, and electrophoresis, which begins with including 500 mL of 10X TBE water solution as its first step.
For Onlabs’s conceptual design, regarding its implementation, but also its evaluation by students with respect to its educational value, the reader may refer to previous publications of ours (cited on our website).
1.2. Liquid Simulation in Onlabs
For experimental procedures such as the aforementioned ones of 10X TBE water solution preparation and electrophoresis, vessels of various forms are involved, such as conical flasks, being wide-necked or not, and volumetric tubes, as shown in
Figure 2a–c. Moreover, in other procedures mainly performed in a chemistry lab, such as the determination of the rate constant of methyl acetate hydrolysis in the presence of acid, more perplexed vessels are used, like burettes, consisting of several different pipe segments, which are straight or curved (
Figure 2d,e).
For those complex vessels, the dynamic creation in Unity (or any other 3D game engine) of the meshes corresponding to the interior liquids is obviously not an easy task. Our technique presented in this paper tackles this problem efficiently with the use of advanced analytical geometry in the 3D space. Afterwards, based on the aforementioned method of liquid simulation, we deal with the simulation of liquid filling of lab vessels of various shapes.
2. Background and Related Work
Over the years, various companies have made significant strides in creating interactive 3D virtual laboratories designed specifically for chemistry and biology education. These virtual labs are characterized by their incorporation of advanced graphics and cutting-edge visual effects, aiming to provide users with an immersive and engaging experience. Among the most prominent examples in this field are Labster (
https://www.labster.com/ accessed on 14 March 2025) and Learnexx 3D (
http://virtualsciencelab.com/index.html accessed on 14 March 2025). These platforms have gained widespread recognition and are extensively used as training tools for both university students and laboratory professionals. Their popularity stems from their ability to simulate experimental workflows in a visually appealing and user-friendly manner.
However, it is important to note that these platforms generally do not prioritize detailed quantitative simulations. Instead, they focus on guiding users through specific actions that produce predetermined outcomes. For example, these simulations might demonstrate how to fill a bottle to capacity or measure the exact amount of a powdered substance required for a given experiment. The primary educational objective of these tools is to familiarize users with the qualitative procedural steps needed to complete an experiment successfully. In this sense, the emphasis is placed on understanding the sequence of actions rather than on achieving precise quantitative results.
On the other hand, there exists another category of chemistry simulations that shifts the focus entirely toward quantitative accuracy and precision. These simulations emphasize tasks such as exact measurements, accurate titrations and even the inclusion of background chemical reactions. A representative application of this kind is ChemCollective Virtual Labs (
https://chemcollective.org/vlabs/ accessed on 14 March 2025). However, while these simulations excel in quantitative realism, they fall short in other areas. Specifically, they are typically confined to two-dimensional environments and lack the interactive depth and visual sophistication found in the first group of virtual labs. Despite their limitations though, the underlying chemistry principles required to develop these simulations can often be encoded into specialized computational engines with relative ease [
1].
Our goal of quantitative chemistry simulations is to address the divide between these two distinct categories of applications. By merging the advanced 3D graphics and high-quality visual effects of the first group with the quantitative precision and accuracy of the second group, we aim to deliver a comprehensive solution that incorporates the best aspects of both approaches.
Our first attempt at quantitative liquid transfer simulation within Onlabs, implemented for version 2.1 and also used in later versions, was based on scaling. Particularly, in order to simulate the aspiration and discarding of liquids from or to a cylindrical vessel with instruments like the electronic and automatic pipettes, the height of the cylinder representing the liquid inside is increased or, respectively, decreased, creating the illusion that the liquid level rises or drops. In the case, though, of a conical vessel, the cone representing the liquid inside is split pre-runtime into several truncated cones of equal volume, and the latter are successively scaled in real time [
2]. While our method deals with most of the vessels in a biology lab, it does not cover vessels and containers with irregular shapes like burettes, described in the introduction. For this reason, we have developed a significantly more advanced liquid transfer simulation technique, which we will present in the following sections, which in turn is based on the method for liquid surface representation also presented in this paper.
In general, achieving a realistic visual outcome in liquid simulations is a rather challenging task. One widely used technique in this domain is fluid animation, which has been extensively applied in commercial computer games. This approach leverages solutions to the complex 3D Navier–Stokes Equations for fluid dynamics, combined with advanced graphical techniques for visualizing fluids. The foundational work in this area was carried out by Foster and Metaxas [
3], whose contributions were heavily influenced by earlier research conducted by Harlow and Wlech [
4] in the field of computational fluid dynamics. Over time, numerous advancements have been made in fluid animation. For instance, Stam [
5,
6] introduced an unconditionally stable model capable of producing intricate, fluid-like flows by efficiently solving the Navier–Stokes equations, enhancing in this way the realism of this kind of simulations significantly.
Another technique frequently used for realistic liquid simulation involves particle systems, which were first conceptualized by Reeves [
7]. Particle systems are a versatile method employed not only for simulating liquids but also for modeling other types of fluids. These systems have become a staple in modern 3D game engines such as Unity, where they are valued for their adaptability and effectiveness in creating visually compelling fluid simulations. Clavet et al. [
8] developed a particle-based method for viscoelastic fluid simulation, with which they simulated, among other phenomena, the splashing of paint, mud or rain drops on moving objects, as well as water fountains and pouring liquids into vessels.
In a different fashion, Medvecký-Heretik used cellular automata in order to realistically simulate liquids within the context of interactive applications (games) while also achieving low memory consumption and maintaining high frame rates [
9].
Despite the advancements and widespread use of these techniques, it is notable that neither fluid animation nor particle systems have been applied to liquid simulations in the context of virtual laboratories, particularly for quantitatively modeling liquid transfers. This absence is not surprising, given the considerable costs associated with these techniques, both in terms of development time and the computational resources required during runtime. Recognizing these challenges, Onlabs has adopted a different approach to liquid transfer simulation. This alternative method circumvents the limitations of traditional techniques, offering a more practical solution tailored to the unique needs of virtual laboratory environments.
3. Materials and Methods
In this section, we describe our full technique for liquid simulation in a virtual lab. First, in
Section 3.1, we address the problem of modeling liquids inside various vessels of complex structure by leveraging advanced analytical geometry. Thereafter, in
Section 3.3, building on that liquid modeling method, we propose an extension to it, which deals with the simulation of liquid filling laboratory vessels of various shapes, while in
Section 3.4 we present its pseudocode. The results from both of those simulation methods’ implementations under Unity/C# are presented in
Section 4.
3.1. Description of Pipes and Bottles with Circular Cross-Sections and Liquid Volume Representation
During the experimental procedure for determining the rate constant of methyl acetate hydrolysis in the presence of an acid (also in all experimental procedures in biology and chemistry laboratories), bottles of various sizes and shapes are extensively used. Instruments with tubes, which facilitate the flow of liquid from one bottle to another, are also employed.
In the experiment of determining the rate constant of methyl acetate hydrolysis in the presence of an acid, examined in this study, there is extensive use of and transfers between conical, cylindrical/volumetric bottles and burettes. Specifically, during the use of an automatic burette, the following processes occur:
Liquid flow through a tube, bottle emptying and volumetric tube filling with free flow during the filling of the automatic burette’s volumetric tube.
Liquid flow through a tube and bottle refilling with free flow from the automatic burette during the zeroing of the volumetric tube’s measurement.
Emptying of the volumetric tube with liquid flow into the spout tube of the automatic burette’s measurement tap.
From the above, the utility and significance of simulating liquid flows, as well as the filling and emptying of bottles with liquids, become evident for enhancing the sense of realism experienced by the student/user. To achieve this, the movement of the liquid as a function of time must be simulated, ensuring this function closely mirrors the actual quantitative and temporal behavior of liquid flow within a tube or bottle.
3.1.1. Types and Classification of Liquid Movement
Liquid movement can be broadly classified, based on the applications of interest, into the following categories:
Steady liquid flow in a tube.
Transient liquid flow in a tube.
Filling and emptying of a bottle.
This work, on top of the proposed graphical representation of liquid surfaces in vessels of various shapes, seeks a unified mathematical approach to describing liquid flow in pipes and bottles by examining the latter’s filling, facilitating seamless implementation in Unity/C#. Specifically, the goal is to parameterize the description of an entire composite pipe, enabling straightforward modeling and simulation across consecutive pipe segments.
3.1.2. Simplifying Assumptions
The following simplifying assumptions were made for describing pipes and bottles:
- 1.
Pipes and bottles are assumed to have only circular cross-sections.
This assumption leverages axial symmetry to simplify the design of the pipe’s inner surface and the outer surface of the liquid volume. By varying only one parameter (the angle) in each cross-section at a fixed step, points can be generated and connected with equal-length straight segments. This results in a uniform discretization of the perimeter of each circular cross-section (
Figure 3).
In contrast, for non-circular cross-sections, solving a system of equations would be required to find perimeter points spaced at equal arc-length intervals. If the shape is polygonal, discretization points must be taken at its vertices to preserve its original form; otherwise, it would be distorted into a different approximation (
Figure 4). For non-axisymmetric shapes, the direction of the shape within the plane of the cross-section must also be considered.
If different cross-section shapes are used within the same composite pipe, discontinuities will arise at the transitions between segments, necessitating computationally expensive special handling.
- 2.
The current length of the pipe/bottle is used as a common parameter and the central line remains continuous at segment transitions (preserving its slope).
The parameter
, representing the current length of the pipe/bottle, is continuous along the entire composite structure and is measured along the line formed by the centers of the circular cross-sections. Additionally, this local length parameter can be used for each individual circular pipe and is related to the global parameter
(
Figure 5). This is a fundamental parameter in the modeling approach.
- 3.
The diameter remains continuous along each pipe/bottle and is preserved at segment transitions.
This assumption allows for a simplified mathematical description of the diameters of each pipe segment using functions and enables the entire composite pipe to be described with only a few parameters (where the end diameter of one segment matches the start diameter of the next).
Additionally, the absence of diameter discontinuities aligns with the real-world construction of pipes and bottles. A discontinuous diameter requires additional parameters, such as the initial or final diameter of each segment, and results in two separate perimeters/cross-sections at each transition point. This disrupts the one-to-one correspondence between the central point and the cross-section required for modeling and implementation.
A sudden diameter change also causes local pressure losses in fluid flow, which must be accounted for in computational calculations.
- 4.
The slope/angle of the central line of the pipes remains continuous along its length and at transitions between segments.
With this assumption, the curvature of the pipe can be described uniformly using a single function. It also facilitates the precise design of the liquid’s outer surface and the pipe’s inner surface, as there are no discontinuities.
Furthermore, this approach simplifies the parameterization of a composite pipe, since the completion angle of the previous segment serves as the starting angle for the next one. This eliminates the need for an additional parameter to define the start or end angle of each pipe segment. Maintaining slope continuity aligns with real-world pipe construction, whereas a discontinuous slope would introduce additional computational costs due to localized pressure losses.
- 5.
The diameter as a function of the pipe/bottle length remains either constant or varies linearly.
This assumption is adopted for simplicity, as most pipes and bottles either follow or can be approximated by such a description. For curved segments, the diameter is chosen to remain constant (
Figure 6). If the diameter were to follow other functions along the pipe length, obtaining analytical expressions for the current length as a function of volume would be more challenging (for conical sections, a cubic equation would need to be solved).
- 6.
The liquid level in pipes and bottles is assumed to be perpendicular to the central line at every point.
The assumption of the perpendicularity of the liquid level to the vessel’s central line at every point (
Figure 7) consists of the basis of the discretization methodology. This approach is sufficient for pipes of any inclination due to the high length-to-diameter ratio:
The liquid level moves at high velocity and has low visual discernibility, making any differences in level undetectable, whether it is perpendicular to the central line or horizontal.
In very thin or rough pipes or in liquids with high viscosity (or a combination of these), capillary effects enforce a perpendicular liquid level relative to the central line.
- 7.
Only vertical bottles are considered.
To ensure a unified description of the pipe’s inner wall and the liquid volume’s outer surface and to maintain a liquid level perpendicular to the bottle’s length, only vertical bottles are considered. Since bottles have a lower length-to-diameter ratio compared to pipes, the liquid level in them is always horizontal (
Figure 8).
Modeling inclined or curved bottles would require complex surface calculations (e.g., computing conic sections). The modeling and implementation rely on discretization points in a cross-section perpendicular to the central line at every point, which cannot be applied to inclined bottles (where the liquid level would not be perpendicular to the central line).
- 8.
The curvature parameter is used for each pipe segment.
To represent both curved and straight pipes consistently, a unified description is required. While the curvature radius tends to infinity for straight pipes, their curvature is zero (since curvature is the inverse of the radius). For curved pipes, curvature is a finite number.
A zero-curvature radius (infinite curvature) would reduce the pipe length to zero (a point), which is physically impossible. However, curvature itself is defined over all real numbers in because its sign determines the rotation direction of the curved pipe’s central line:
- 9.
The curvature radius of the central line of each pipe segment must be at least equal to or greater than the cross-sectional radius.
This assumption ensures that, when defining points for finite triangular surface elements, new points are generated only along the movement direction of the liquid level/central line for each pipe cross-section. This is also required from a manufacturing perspective, as a curved pipe must have at least one interior surface point along its bend. It is therefore structurally necessary and must be adhered to when inputting parameters or enforced by the implementation.
Figure 9 illustrates all three possible cases of curvature radius being greater than, equal to, or smaller than the cross-sectional radius, while
Figure 10 shows an example of a 90° curved conduit surface where the curvature radius is half the cross-sectional radius.
- 10.
The central line of the composite pipe is assumed to lie within a plane.
This approach is used because it significantly simplifies the formulation of equations for positioning points along the central line and the cross-section perimeter. Additionally, this assumption is suitable for the modeling application in the automatic burette.
Although the implementation could support a central line in three-dimensional space, it would require more complex equations and higher computational costs. For example, curvature would need to be represented as a vector quantity rather than just a scalar magnitude and direction. In a plane, curvature requires only a magnitude and direction, whereas in three-dimensional space, it must also have an orientation within the plane of the initial cross-section of the curved conduit.
Essentially, the aim is to determine the equations describing the coordinates of any point along the central line in the plane and the pipe’s slope at that point. This enables drawing the corresponding liquid level at that specific point.
3.1.3. Central Line Coordinate Equations for Curved Pipes with Constant Diameter and Straight Pipes with Constant or Linearly Varying Diameter
Recall that a composite pipe consists of various segments, some straight and some curved. To position each segment of the composite pipe in the plane, we initially identify a single point—the starting point of the segment’s central line. Naturally, the endpoint of one segment serves as the starting point for the next, so only the initial points of consecutive segments need to be specified. For each starting point of a pipe segment’s central line, the parameters that must be measured or determined include its horizontal and vertical coordinates and the slope (angle) of the central line relative to the horizontal plane.
Once these three values (horizontal coordinate, vertical coordinate and slope) are defined for the start of a pipe segment, they can be used to calculate corresponding values for any arbitrary point along that segment. This is the basis for fully defining the positioning of the segment in the plane.
Let’s assume that the horizontal coordinate, vertical coordinate and slope at point A of the central line of a curved segment of the burette’s composite pipe are known. To calculate the corresponding values at another arbitrary point B along the same segment, refer to
Figure 11 for illustration.
According to
Figure 11b, the angle, horizontal coordinate y and vertical coordinate of point B are given by the following equations:
The angle
is defined such that its sides are perpendicular to those of the angle
θs/2, leading to:
For the angle
, considering that the curvature
equals
, we have
As for the length
, it is calculated as follows:
Substituting
,
and
from Equations (4), (5) and (6) into Equations (1), (2) and (3), respectively, we derive the following expressions for the coordinates and angle of point B:
For straight pipe segments, the above equations degenerate into the following:
Equations (10)–(12) for straight pipe segments apply not only to the straight sections of the composite pipe of the burette but also to volumetric cylinders and conical flasks, whether wide-necked or not.
3.1.4. Geometric and Mathematical Description of the Coordinates of the Perimeter of a Pipe or Vessel with an Inclined Circular Cross-Section
Initially, we will describe the mathematical coordinates of a random point C on the liquid’s perimeter in a pipe with an inclined circular cross-section, as shown in
Figure 12. (We remind that according to our assumption, the cross-section of a pipe with the horizontal level is always circular.) Knowing the coordinates of the points on the circular perimeter, we can later, in Unity, draw a polygonal approximation of the latter. By successively drawing the perimeters corresponding to each point on the central line, we have the full liquid lateral surface inside the pipe.
In order for the calculation to be done, the diagram in
Figure 12 is deployed into the ones of
Figure 13.
Now, according to
Figure 13b, when the cross-section is inclined by angle θ,
can be analyzed into
and
as follows:
Combining Equations (14) and (15) with the z-coordinate of the point on the central line of the cross-section, and Equations (14) and (16) with the y-coordinate of the same point on the central line of the cross-section, we derive the general Equations for the points of the circular perimeter in 3D space:
We remind that is already given in Equation (13).
3.2. Discretization of Pipes and Bottles’ Cross-Sections
In
Section 3.1.3 and
Section 3.1.4, we calculated the equations for the coordinates of any point on a central line as well as the equations for the coordinates of the respective points on the central line’s circular cross-section with the horizontal level. Having done so, we can dynamically create in Unity the meshes of the interior liquids of the various vessels of our simulation.
However, the circles upon which the liquid mesh creation is made cannot obviously be drawn as such. Instead, we approximate those with polygons through a process called discretization. The latter depends heavily on the number of vertices we decide our polygons to have (
Figure 14).
Figure 15 shows the notation for points in each cross-sectional circle.
Specifically, in
Figure 15,
represents the cross-section number, ranging from 0 to the total number of cross-sections minus 1, while
denotes the sequential number of the point within each cross-section, ranging from 1 to the total number
of discretization intervals.
The number , chosen by the developer of the simulation, applies to all cross-sections and determines the fidelity of the circle representation. In the example above, the value of equals 4.
The coordinates of the aforementioned points will be calculated based on angular intervals of at angles . In this specific example, the angles are , , and . For these angles, using the radius of the circle of the current cross-section, the inclination of the cross-section, the coordinates of the circle’s center (the central line point) and Equations (13), (17) and (18), the coordinates of each discretized point of the circle/cross-section are computed.
This method of notation—continuous sequential numbering of the discretized points of cross-sectional circles—was mandated by the way points are defined in Unity’s method for creating triangular finite surface elements. In this method, the sequential number of each point is declared in a one-dimensional array whose elements are the above 3D points (Vector3 variable type).
3.2.1. Definition of Triangular Surface Finite Elements Using Cross-Section Points
The following figures illustrate possible combinations of points forming surface finite triangles. Connections are chosen only between neighboring points within the same cross-section and points at adjacent angles between neighboring cross-sections, as shown in
Figure 16.
Each point on the last cross-section can participate in two to four triangular elements. Each line connecting points of adjacent cross-sections at the same angle forms the edge of exactly two triangular elements. Consequently, the total number of triangular elements equals .
Each such line can participate in three different triangular element combinations; that is, one edge of each triangle always starts in one cross-section and ends in the neighboring cross-section and at a neighboring angle:
Triangles with one edge in the previous cross-section.
Triangles with one edge in the last cross-section.
Triangles with edges in different cross-sections.
Figure 17 illustrates the triangle combinations for each edge between cross-sections at the same angle.
To ensure the visible side of the triangle (the outer surface in this application) appears in Unity, the order of point declaration for the triangle must follow a clockwise sequence (
Figure 18a).
3.2.2. Mathematical Handling and Implementation Specifics of Triangles Between Cross-Sections
The diameters (
d) of pipes/bottles (half of which is the radius
r used in the circle coordinate equations for inclined cross-sections) as well as the lengths (
l) and the curvatures (
κ) of the central lines are stored as data in a description matrix.
To account for potential tapering in the first section, the initial diameter must also be declared. For subsequent sections, since continuity between sections is assumed, the initial diameter of a section is determined by the final diameter of the previous section. For instance, for the second section, the initial diameter is and the final diameter is .
Using the initial diameter of the composite pipe, the initial slope and the starting coordinates of the central line, discretization points are generated in the initial cross-section to form the first triangular surface finite elements using the discretization points of the initial cross-section (excluding the start point).
The surface between two points on the central line is created through the following steps:
Assuming a sufficiently small step length for the central line and incrementally increasing the current length in a loop.
Calculating the coordinates of the central line point corresponding to the current length at each iteration.
Based on the above coordinates, iteratively calculating the discretization points of the cross-section’s perimeter using angular intervals (as determined by the chosen resolution). These points are recorded sequentially in a one-dimensional array.
Using the discretization points of the previous and current cross-sections, triangular surface finite elements are created by recording the sequential numbers of each point in the previous array. Each set of three points, in order, forms a triangular element. The two arrays are assigned as corresponding vertex and edge attributes in a mesh structure.
To minimize iterations and algorithm execution time (thereby reducing time between iterations, improving dynamic simulation of level variations and increasing surface accuracy), the grouping of vertices for triangle creation is further analyzed. That is, the existence of a possible pattern for the set of each cross-section is investigated so that the implementation can be included in the existing point/peak generation loop.
For each cross-section
, starting from the first defined point
, the following two triangular finite elements can be declared using points from the previous cross-section:
For the next point
, combinations with points incrementally higher than those in the previous sets are tested:
Following this approach, triangular finite elements are defined sequentially for the last point in the current cross-section:
Figure 19 illustrates a graphical depiction of the sequence for recording/representing the triangular finite elements for each point of a cross-section with 4 discretization points.
In
Figure 19, the triangles that can be defined after creating the first point of the new cross-section (point 5) are shown. Thereby, the two created triangles for point 5 are
Next, the triangles for the remaining three points of the cross-section are created (at this point, in addition to the points from the previous cross-section, the neighboring points of the new cross-section that have already been created are available).
Thus, the triangles for point 6 (
Figure 20) are
Next come the triangles for point 7 (
Figure 21), which are
Finally, the triangles for point 8, which is the last point of the cross-section (
Figure 22) are
In total, we have the following pairs of triangles for each of the points 5, 6, 7 and 8:
It is easily observed that for a point with a total serial number
and with
being the number of discretization points in each cross-section, a numerical pattern is followed for the point’s two triangles:
For the next point
, the numbers in the above triplets forming the finite triangular elements are increased by 1 (that is, the next point from the corresponding triplets of the previous point is recorded):
This pattern can be directly utilized in implementation to generate the finite surfaces simultaneously, without requiring a new loop, during the creation of discretization points for each cross-section.
3.3. Simulation of Dynamic Flow and Liquid Level Variation in Bottles and Tubes
As mentioned in
Section 3.1, the developed methodology for modeling the surface of tubes and liquids aims to define the surface as a function of a single variable, that of the current local length of the bottle or tube segment. By knowing the current local length—representing the liquid level for bottles or the volume in general for the container (bottle or tube)—and the characteristic data of the container (from the corresponding registry), the current diameter and local slope of the container at every point along its centerline are calculated accordingly. This approach enables the generation of the corresponding surface from the base to the current length of the container.
The goal of this modeling effort has been, from the outset, the dynamic simulation of liquid level variation during filling or removal from the container. The developed methodology successfully separates the implementation of surface creation from the mathematical modeling of the one-dimensional dynamic liquid flow (which dynamically provides the current liquid volume in each container).
The remaining task is to mathematically calculate the local liquid level (the current length) in each circular cross-section container, assuming that the simplifying assumptions outlined in
Section 3.1.2 are adhered to. The resulting function for calculating the local current length and slope is used as input to the implementation described in
Section 3.1 to design the corresponding surface as its outcome.
The mathematical modeling of liquid flow is achieved using fluid mechanics equations. Subsequently, a mathematical approach is presented for modeling the filling of a bottle under a known liquid volume flow rate.
In cases where the filling occurs with a known liquid volume flow rate over time, the bottle is filled by transferring liquid via free flow (without losses and at atmospheric pressure) from a different container.
To calculate the instantaneous liquid volume flow rate into the target bottle, it suffices to know the outflow velocity, the cross-sectional area of the outflow opening of the supply container and the proportion of volumetric outflow directed into the target bottle. The instantaneous flow rate is given as the product of these three factors, which can be determined by solving a system of fluid mechanics equations for the flow within the supply container.
3.3.1. Geometric and Mathematical Description of Bottle and Composite Pipe Levels and Liquid Length Dimension with Respect to a Known Liquid Flow Rate
Given a liquid flow rate—either constant or expressed as a time-dependent function—and knowing the time step of each iteration of the simulation loop (handled by a C# Unity function), the additional volume added to the tube between the previous and current iterations can be calculated. In this sense, the volume is treated as a known quantity.
Figure 23 shows a schematic representation of a tube with an increasing diameter cross-section.
The volume
between two levels,
and
, as shown in
Figure 23, is given by
To relate parameter
with the levels and diameters, the tangent of angle
is used:
The linear function of diameter with respect to the level/point on the central axis of the tube is expressed as
where the parameter
equals the tangent of the cone angle
:
In Equation (19), we substitute with its value from Equation (20); we then substitute and with their values from Equation (21) for s, being and , respectively; and finally, we rearrange all terms to one side of the equation, simplifying into terms of (the level of interest).
The resulting equation becomes
Equation (23) is a complete cubic polynomial of the form
The discriminant
is calculated as
Substituting the coefficients, the discriminant becomes
Since is always negative, the equation has one real solution and two conjugate complex roots. This result is desirable because, in other cases, there could be either three distinct real roots or one double real root and one single real root. The real root provides the exact analytical expression for the new liquid level based on the given data and the previous known level.
The general solution for Equation (24) is
Substituting the coefficients from Equation (23), the real solution simplifies to
Verification of this solution by substitution into Equation (23) shows the left-hand side becomes zero, confirming its correctness. Simplifying by cubing both sides and rearranging terms verifies the equivalence to Equation (23).
We will now consider the case of the truncated conical tube of decreasing diameter, according to the schematic representation of
Figure 24.
Using the tangent of angle
ψ to relate
h to the other parameters, we get
The same process applied to Equation (28) results in a cubic polynomial identical to Equation (23). Hence, its solution is also identical to Equation (27).
For completeness, the case of a straight tube with constant cross-sectional diameter is included. For this case, therefore, we have
We will now express the volume of a curved pipe section as a function of its length.
We know from calculus [
10] that the volume V of a solid of revolution, where the cross-sectional area is bounded by the functions
and
, is given for the segment of the solid between heights α and β by the following integral:
In our case, we are interested in the volume of liquid within a segment of circular cross-section, as illustrated in
Figure 25.
The upper semicircle in the said figure is expressed as
while the lower semicircle is expressed as
For rotation through an angle
, the volume
is expressed as
By substituting
, we get
If we further replace with and with , the equations remain consistent with Equations (30) and (32), which also hold for cylindrical volumes.
3.3.2. Key Points and Implementation Examples for Bottle and Composite Pipe Filling in Unity
The modeling and implementation of surface creation accept the following as input parameters for the initial cross-section characteristics:
Coordinates of the central line point of the initial cross-section;
Slope of the initial cross-section/
Diameter of the initial cross-section.
In the implementation, it is necessary to retrieve the time interval that has elapsed since the previous iteration of the execution loop in the corresponding Unity C# script.
The implementation requires tracking and monitoring of the following variables:
The current volume of liquid in the bottle;
The cumulative volume that each segment of the bottle can contain.
This information is critical to determine the segment of the bottle where the liquid level will rise after adding the new volume to the existing volume of liquid. Specifically, if the flow rate is sufficiently high (or the segment volume is sufficiently small) so that within the time interval between two loop iterations, the liquid level can move through one or more segments, the surface can be rendered for all such segments up to the level of the current segment.
At the beginning of the implementation code (during the initialization function) and before the execution loop starts, the cumulative volumes stored from the bottom of the bottle to each segment are calculated and recorded.
The volume of a frustum of a cone with
and
being its bases and
its height (
Figure 23) is given by the following formula:
If, in Equation (32), and are replaced by d (for a bottle segment with a constant cross-sectional diameter) and the length l is replaced by , then the equation becomes identical to Equation (30).
Thus, Equation (32) can be used to calculate the individual volumes of all types of bottle segments examined in this study (constant-diameter, either straight and curved, or straight with linearly varying diameter shapes).
Before the execution loop begins, the points of the pipe’s initial cross-section are created, and if an initial liquid level exists, the points of the cross-section at the initial liquid level and the surface between them are also created. Finally, the initial volume is calculated (this functionality has been implemented for an initial level in the first segment). During the execution loop, based on the given liquid flow rate, the new volume of liquid to be added to the pipe for each time interval between iterations is calculated as
. The new total current volume is then compared with the cumulative volumes up to each segment to determine in which segment the new liquid level will be located:
Two cases are therefore distinguished: If the new volume remains in the same segment as the previous one, the new liquid level is calculated using
in place of
and the initial liquid level of the current segment in place of
in either Equation (27) or (31), depending on whether the segment’s diameter is variable or constant. Otherwise, if the new volume spans multiple segments and if the new volume exceeds the total volume of the composite bottle, the entire bottle surface is rendered and the loop execution is terminated. If not, the surfaces up to the previous segment are rendered and the local volume for the current segment is calculated as
This value is then substituted back into either Equation (27) or Equation (31), depending on whether the segment’s diameter is variable or constant (where , the initial level, is replaced with zero).
3.4. Pseudocode
The pseudocode for our method in whole, that is, both liquid graphical generation and flow simulation, is given in
Table 1.
4. Results
In this section, we present the implementation results of our techniques in Unity (version 2022.3.54f1). First, we illustrate various shapes of liquids (literally, the outside surfaces of liquids inside vessels of various shapes) implemented under our liquid simulation technique and the discretization process for their circular cross-sections (
Figure 26,
Figure 27,
Figure 28 and
Figure 29). Afterwards, we show the outcomes of our dynamical flow simulation technique through consequent screenshots from the filling of vessels of various forms.
To our knowledge, the only quantitative liquid simulation method for conical vessels has been our own, much simpler method [
2], mentioned in
Section 2, and there has not been any for vessels with curved pipes like burettes. Therefore, comparison baselines are not applicable for the time being.
Unity requires the definition of unit normal vectors at each point of a mesh’s surface (through the mesh.normals property of the mesh structure). These vectors are used to determine shading and reflected lighting on the surfaces, providing the illusion of curvature even on individual triangles. In this implementation and the examples provided, Unity’s built-in method mesh.RecalculateNormals() was utilized. This method calculates the appropriate unit normal vectors for the created mesh.
The Unity implementation described here is based on the implementations available on the Flick website [
11].
We now present video screenshots of the implementation of the liquid filling for three kinds of vessels, conical flask, wide-neck conical flask and volumetric tube, already discussed in previous sections, with a volume flow rate equal to 10,000 mm
3/s (
Figure 30,
Figure 31 and
Figure 32).
Table 2 shows the calculations of the volumes of the bottles and the time they are expected to be fully filled, according to the assumed volume supply.
Hence, we observe the following:
The conical flask is filled from the 3rd to the 26th second, a duration of 23 s, which aligns approximately with the calculation in
Table 2.
The graduated cylinder is filled from the 1st to the 14th second, a duration of 13 s, which also matches the calculation in
Table 2.
The wide-necked conical flask is filled from the 2nd to the 32nd second, a duration of 30 s, again consistent with the calculation in
Table 2.
This confirms the accuracy of the simulation and modeling of the filling process achieved by this implementation.
Finally, the result of simulating the filling process of the conical flask, along with the time intervals in seconds for a flow rate of 1,000,000 mm
3/s (1 L/s), is presented in
Figure 33.
At this flow rate, it takes approximately 0.22 s to fill the first segment. It is observed that during the first iteration, the time duration is 0.02 s and 20,000 mm3 of the approximately 222,500 mm3 of the first segment and the total of approximately 229,000 mm3 of the flask are filled. In the second iteration, after 0.33 s, 330,000 mm3 could potentially be filled, but only 209,000 mm3 remain to fill the entire flask. The implementation determines the segment in which the liquid level should now be located based on the new total liquid volume and simultaneously fills each segment that is exceeded by the new volume. Once it determines that the total flask volume has been exceeded, the execution loop terminates.
It is noted that with the current implementation, the average time duration between iterations of the execution and rendering loop ranges between 0.017 and 0.036 s, using an NVIDIA GeForce GT 740M graphics card and an i5-4200 CPU at 1.60Ghz, with 8GB RAM.
Additionally, the image processing frequency of the human eye–brain combination ranges between 30 and 60 frames per second [
12], indicating that the minimum time interval perceptible by the brain between two images is between 0.0166 and 0.0333 s. Thus, in terms of the sense of continuity and realism of motion, the implementation is considered satisfactory.
5. Discussions
In this study, we proposed an algorithmic method for the graphical representation of liquid surfaces and the simulation of liquid flow within laboratory vessels (particularly, their filling).
The method focused on bottles and tubes with circular cross-sections of constant or linearly varying diameter (conical flasks and tubes). The flow in curved tubes was also examined. The flasks studied were vertical, while the central lines of the tubes lied in a common plane. The filling of flasks was simulated using precise expressions that describe it.
Potential extensions could include the following:
Implementing the simulation of flask emptying (the same expressions apply, but adjustments would be needed in handling, such as the surface mesh).
Accurate modeling of filling and emptying flasks with varying diameters using other analytical functions of the pipe length, apart from the linear function.
The filling of pipes and bottles with a given volumetric liquid flow rate was modeled using precise expressions, and the result was algorithmically simulated in Unity. On the other hand, the dynamic liquid flow in a tube would offer many improvements and extensions, such as the following:
Combining energy conservation equations, mass conservation, loss calculations and the ideal gas law for air to derive an analytical solution for the liquid–air interface velocity in order to model and simulate the actual operation of the automatic burette.
Extending the modeling equations to describe the same types of tubes in space rather than only in the plane.
Utilizing the PISO algorithm (Pressure-Implicit with Splitting of Operators) with exact dynamic flow equations for real-time implementation.
Further extending the tube shapes to other analytical functions of circular cross-section diameter beyond the linearly varying and constant ones.
From an implementation perspective in C#, lists are the ideal dynamic data structure for reducing computational time and space. In this study though, a dynamic array was used. Nevertheless, regardless of the use of dynamic data structures, current implementations can be significantly improved, as many iterative structures and control structures of procedural programming are used, and no particular emphasis was placed on optimizing the simulation implementations.
It would be possible to implement functionality such that, based on the tube characteristics provided as input, the algorithm calculates local loss coefficients independently according to relevant rules.
Moreover, a significant enhancement to the capabilities of a dynamic liquid flow/level simulation application would involve separating the following into distinct functions with the ability to collaborate:
Modeling the coordinates and slopes of each point of a tube’s central line.
Identifying the type of tube through analytical expressions for cross-section diameter variation and generating surface point meshes.
Creating finite triangles and representing the surface using them.
Finally, beyond the mere liquid rendering in vessels and flow simulation, other extensions might be explored, such as the sound engineering of liquid flow (e.g., inside a pipe), liquid collision (e.g., pouring water into a filled vessel) and liquid splashing on a solid surface (a proposed technique for the latter being the liquid–solid interaction sound synthesis [
13]).