patchy v200

A library by Jonathan Feinberg for the programming environment processing. Last update, 07/19/2013.

Patchy provides an easy-to-use bicubic patch for 3D graphics in the Processing programming environment.

Acknowledgements

I learned how to calculate bicubic surfaces by reading the course material that Ken Perlin so kindly provides. Part of Patchy is based on his code, and I am very grateful for it.

I learned how to calculate vertex normals, and how to choose vertexes for triangles when rendering, by studying this code, by Tomasz Kaczmarzyk (tom3k). Tomasz was kind enough to explicitly license that code under the Apache 2.0 license, so that I could freely share my work. Thank you, tom3k.

Download

Download patchy version 200 in .zip format.

Installation

Unzip and put the extracted patchy folder into the libraries folder of your processing sketches. Reference and examples are included in the patchy folder.

Patch Types (Basis Matrices)

Patchy.BEZIER
Patchy.BSPLINE
Patchy.CATMULL_ROM
Patchy.HERMITE

Constructing a Patch or PatchGroup

// control points as a 4x4 matrix of PVectors
Patch.create(double[][] basis, PVector[][] controlPoints, int gridSteps);
Patch.create(double[][] basis, PVector[][] controlPoints);  // default 20 grid steps

// control points as three 4x4 matrices of x, y, and z coordinates
Patch.create(double[][] basis,
             double[][] cpX, double[][] cpY, double[][] cpZ,
             int gridSteps);
Patch.create(double[][] basis,
             double[][] cpX, double[][] cpY, double[][] cpZ);

// the same but with floats, which are more Processing-friendly
Patch.create(double[][] basis,
             float[][] cpX, float[][] cpY, float[][] cpZ,
             int gridSteps);
Patch.create(double[][] basis,
             float[][] cpX, float[][] cpY, float[][] cpZ);

PatchGroup group = new PatchGroup();
group.add(p1);
group.add(p2);

Drawing a Patch or PatchGroup

void draw(PApplet p); // uses current stroke, fill, and transforms
void drawControlPoints(PApplet p);  // useful for debugging

Other Useful Methods on Patch and PatchGroup

BoundingVolume getBounds();  // for figuring out scale and position
BoundingVolume scale(double s); // scales the patch or group in-place
void translate(double dx, double dy, double dz);  // translates the patch or group in-place
void setBasis(double[][] basisMatrix);
void setGridSteps(int steps); // change the resolution of the rendered mesh

Methods on Patch (but not PatchGroup)

void set(int row, int col, double xVal, double yVal, double zVal);
void set(int row, int col, PVector p);
void setX(int row, int col, double val);
void setY(int row, int col, double val);
void setZ(int row, int col, double val);

Keywords bicubic,patch,Bezier,Hermite,Catmull-Rom,BSpline,parametric surface

Reference. Have a look at the javadoc reference here. a copy of the reference is included in the .zip as well.

Source. The source code of patchy is available at GitHub, and its repository can be browsed here. Fork it and fix it!

Tested

Platform Windows
Processing 2.0
Dependencies