# Metaballs

(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)

Metaballs
Field: Calculus
Image Created By: [[Author:| ]]

Metaballs

Metaballs are a visualization of a level set of an n-dimensional function

# Basic Description

To visualize a 2D field of metaballs, one can loop through every pixel on the screen and sum the value of each metaball at the current pixel. If this value is greater than or equal to some thresholding value, then the pixel is colored.

# A More Mathematical Explanation

Let $x, x_{0} \in R^{n}$. A typical function chosen for a metaball at location U [...]

Let $x, x_{0} \in R^{n}$. A typical function chosen for a metaball at location $x_{0}$ is $f(x)=\frac{1}{\parallel x - x_{0} \parallel ^{2}}$.

The following is pseudocode to render a 2D field of metaballs:

for y from 0 to height
for x from 0 to width
sum := 0;
foreach metaball in metaballs
sum := sum + 1.0 / ( ( x - metaball.x0 )^2 + ( y - metaball.y0 )^2 );
if sum >= threshold then
colorPixel( x, y );


Alternatively, any function of the form $f(x)=\frac{1}{\parallel x - x_{0} \parallel ^{2k}}$ can be used, with higher values of k causing the metaballs to take on the shape of a square.

## Demonstration

At the top half of the applet the metaballs are visible. The graph at the bottom corresponds to the a cross section of the metaball field at the red line in the top half.

If you can see this message, you do not have the Java software required to view the applet.

[[Category:]]