• 沒有找到結果。

Ice Melting Simulation

4.2 Find Isosurface for Metaballs

We separate the ice particles and water particles, and use different ways to test inter-section for them. Here we introduce the method used for testing the interinter-section for water particles. The method is based on the method proposed by Kanamori et al. [KSN08], and they use a metaball to represent a water particle.

To render the shape of the metaballs smoothly, the isosurface of these metaballs can be found using ray tracing with the special principles of judgment. Each metaball has a density field, and a set of nearby metaballs represents a smooth surface by the way of combining their density fields. In the following sections, we will introduce the method to find the isosurface for the metaballs.

4.2.1 Field function of metaballs

Figure 4.3: A sketch of the field function fi.

We use the density field function fi to represent the metaball i based on the distance r from the central of metaball Pito the point x, as shown in Figure 4.3. The fi has a finite

support Ri, and Rirepresents the effective radius of metaball i. Thus, fi(r) = 0 if r ≥ Ri. For N metaballs, the shape of the isosurface is defined by the point x∈ R3 in below:

f (x) =

N−1 i=0

qifi(∥x − Pi∥) − T = 0, (4.2)

where T is a threshold, and{qi} are the density coefficients. The normal vector at x can be derived from−∇f(x).

The Nishita and Nakamae's algorithm [NN94] converts the function fiinto the Bézier curve form, and uses Bézier clipping to solve equation with quadratic and degree-six poly-nomial. Here we use the degree-six polynomial, and it has seven control points. The equation of Bézier curve is shown as below:

fi(si) =

6 k=0

dikBk6(si), (4.3)

where si ∈ [0, 1] is an intersected interval, B represents the Bernstein polynomial, Bkn(u) = (n

k

)uk(1− u)n−k, and (k

6, dik)(k = 0, 1, ..., 6) is the coordinates of the control points of Bézier curve. When the Bézier curve represents one metaball, the control point is set as following:

d0 = d1 = d5 = d6 = 0, d2 = d4 = 16

27a2i, d3 = (8ai+ 5)a2i

45 , (4.4)

where ai is the length of the intersected interval D

R2i , and D is the discriminate from the formula of ray-metaball intersection test.

4.2.2 Framework for rendering metaballs

The isosurface of these metaballs will be found using a special ray tracing algorithm.

Figure 4.4 shows the sketch map for rendering metaballs. B0and B1are two nearby meta-balls, and R0is a incident ray intersecting the surface of these two metaballs at{t0, ..., t3}.

We detect the ray-isosurface intersection point from the first interval [t0, t1] to the last in-terval [t2, t3] using Bézier clipping. This process stops when an intersection is found or no intersection is found.

Figure 4.4: A sketch for rendering metaballs.

In each interval, the Bézier curves of the influential spheres are summed into one curve. For instance in the Figure 4.4, the interval [t1, t2] is effected by the B0 and B1 at the same time, so the Bézier curve f01 in the interval [t1, t2] is constructed by combining two curves f0 and f1 which represents B0 and B1 respectively. It is simple to combine multiple Bézier curves, since all we need to do is add each control points dikbelonging to each influential spheres; i.e.:

d01k = d0k+ d1k, (k = 0, ..., 6) (4.5)

4.2.3 Bézier clipping

Figure 4.5: A Bézier curve with five control points. (a) is the Bézier curve before clipping, and (b) is the curve after clipping.

We use Bézier clipping method [NN94] to iteratively compute the root fi(si)−T = 0,

as shown in Figure 4.5. The Bézier curve is always inside the convex hull formed by its control points dik. The two intersection points between convex hull and horizontal line s = T is smin and smax. Therefore, we find [smin, smax] iteratively and finally we can converge to the root.

In each new interval, we want to obtain new control points for new curve, as shown in Figure 4.5(b). The de Casteljau's Algorithm is utilized here. Also, we use the Jarvis March algorithm to obtain convex hull for curve. These two algorithms will be illustrated in the following section

4.2.4 The de Casteljau's algorithm

The de Casteljau's algorithm is used to obtain new control points for the new curve.

If we have the original control points dk(k = 0, ..., n) and the new interval [smin, smax], we can use this algorithm to get the new control points dk(k = 0, ..., n).

The process of the de Casteljau's Algorithm as below:

1. For any nth order Bézier curve, this algorithm starts with the point set{pk= dk}, which contains exactly n + 1 elements.

2. It then replaces this set with an interpolated set{p0 = point between p0 and p1 at distance t, p1 = point between p1 and p2 at distance t, ..., pn−1 = point between pn−1 and pn at distance t}, where t is the position we want to find on the original interval. This set will be 1 element shorter than pk.

3. Step 2 is repeated until there is only one point left, and that point will lie on the original curve, at the same t value.

In this process, the new control points are found at interval [0, t] or [t, 1]. An example is shown on Figure 4.6, assuming point set pk(k = 3).

For the new interval [smin, smax], we run this algorithm two times. In the first time, we set the smin as t, and find the new control points at interval [t, 1]. Therefore, we get a new interval [smin, 1]. In the second time of computation, we set the smaxas t, and we find

Figure 4.6: Finding control points for new curve at interval [0, t] or [t, 1].

the new control points at [0, t]. These new control points are the solution dk at interval [smin, smax].

4.2.5 Jarvis march algorithm

The property of Bézier curve is that we can use a convex hull to cover the curve, and the convex hull is made by control points. Therefore, we use Jarvis March algorithm to find the convex hull for the curve. Jarvis March algorithm is a simple method that forms edges, and checks that every point is on the same side. The following is the process of algorithm:

1. We assume a virtual first point pv to act as the initial reference.

2. We connect pv and p0 to a line L0, where p0 is the first point of point set P . p0 is regarded as a judgment point pf ront.

3. We find the biggest angle for L0and Li, where Liis a line constructed by pf rontand the point pifrom the set P . The point pi will be pushed into hull set H if Lihas the biggest angle. Then, Libecomes L0, and piturns into pf ront.

4. Step 3 is repeated until pf ront points to h0, where h0 is the first element in hull set H, and then we find the necessary points of the convex hull which are in the hull set H.

Here is an example with six points, shown in Figure 4.7.

Figure 4.7: Example of Jarvis March algorithm. The blue line is L0, black lines are the necessary lines, gray lines and red line are Li, and red line is the line with the biggest angle calculated with counterclockwise.

4.2.6 Algorithm

We illustrate the process for rendering N metaballs. We render the scene with many rays, and the algorithm is processed for each ray, as shown in Figure 4.8.

In the beginning, we shoot a ray from the view target and perform intersection tests with all the metaballs. The metaball which is intersected have even number of intersection points. We sort the intersection points of all intersected metaballs and construct k intervals.

For each interval i, we collect influential metaballs in a set and calculate the control points using de Casteljau's algorithm for these metaballs. To combine multiple Bézier curves, we add each control points dikbelonging to the set of influential metaball and construct a new curve. If all the control points are smaller or bigger than threshold T , then there is no intersection between the convex hull and the horizontal line s = T , so we go to the interval i+1. Otherwise, we will do the Bézier clipping and find the new interval [smin, smax] until the interval size is small enough (i.e. smaller than ε, where ε is a very small number). The

Figure 4.8: Flow chart of metaballs rendering.

vector scalar t for ray direction is calculated by t = ti + (ti+1 − ti)∗ smin. Therefore, we can obtain the exact intersect position Ip between ray and metaballs by utilizing the following equation:

Ip = Vp+ tD, (4.6)

where Vp is the position of view target, and D is the direction vector of the ray.

相關文件