Skip to content
thothbot edited this page Mar 4, 2016 · 9 revisions

Parametric Geometry

Class ParametricGeometry is very very useful to generate parametric surfaces by defining custom function.

Constructor takes three arguments:

  • a function object that converts the domain coordinate into a range coordinate;
  • the level-of-detail for the U coordinate;
  • and the level-of-detail for the V coordinate.
ParametricGeometry geometry = new ParametricGeometry(
    new ParametricGeometry.ParametricFunction() 
    {	
        @Override
        // Converts the domain coordinate into a range coordinate
	public Vector3 run(double u, double v)
	{
            /* code */
        }
    },
    slices, // The level-of-detail for the U coordinate
    stacks // The level-of-detail for the V coordinate
);

Lets implement ParametricFunction interface and write function to create a sphere:

@Override
public Vector3 run(double u, double v)
{
    u *= Math.PI;
    v *= 2 * Math.PI;

    double x = Math.sin(u) * Math.cos(v);
    double y = Math.sin(u) * Math.sin(v);
    double z = Math.cos(u);

    return new Vector3(x, y, z);
}

Built-In Geometries

This is family of the following classes, which are inherited from the ParametricGeometry

Klein bottle

 KleinParametricGeometry geometry = new KleinParametricGeometry(10, 20);

Flat Mobius strip

 MobiusParametricGeometry geometry = new MobiusParametricGeometry(10, 20);

Mobius 3D

 Mobius3dParametricGeometry geometry = new Mobius3dParametricGeometry(10, 20);
Clone this wiki locally