BezierPatchApplet - Project Description

Overview
This applet makes use of many different features of the Java language. Drawing the Bézier patch involves interacting with the GUI, using Java's graphics subsystem, and performing a great deal of calculation. Developing the applet and integrating everything was a learning experience that increased my familiarity with Java. The functionality and performance of the applet are a tribute to Java's capabilities.

Areas of Interest
Multi-threading - To increase the applet's responsiveness and allow user input during calculations, a dedicated rendering thread is used. This thread is designed to be CPU-friendly; during times of rapid inputs, it will draw the patch based on the most recent data (thereby avoiding a great deal of unnecessary calculations). In addition, the rendering thread has a built-in "sleep-time" during which it gives up the processor and allows other applications a chance to execute.
Progressive display - In accordance with the applet's CPU-friendly attitude, the Bézier patch is displayed incrementally. By drawing a low-detail patch quickly, users are able to get a feel for the overall shape of the patch without having to wait until all the details have been computed. Therefore users are able to receive feedback quickly without having to sacrifice image quality.
Three-dimensional view - To fully appreciate the Bézier patches this applet generates, one should view them from a variety of perspectives. To facilitate in-depth exploration, the applet contains a three-dimensional rendering engine. The viewing direction is constrained to always look at the patch, but users can place the viewpoint anywhere they choose. Because the easy-to-understand spherical coordinate system is used, even people unfamiliar with three-dimensional viewing systems are able to quickly begin experimenting.
Click-and-drag the control points directly - Though each control point has a scroll bar that controls its height, it is often easier for users to click directly on the control points. Consequently, the applet tracks mouse input and automatically updates the patch and scroll bars as users click-and-drag. By handling mouse input in addition to scroll bar manipulations, the applet is able to accommodate varying user preferences.
Double-buffering - To avoid presenting ugly (and potentially confusing) half-drawn images, the applet double-buffers all graphics output. Double-buffering works by maintaining two images: a foreground image and a background image. All drawing takes place on the background image; the foreground image, which is being displayed, remains untouched. When drawing has been completed, the finished background image is swapped with the foreground image. Therefore, users are presented with only finished images and do not have to put up with flicker or partially drawn images.
Two patches - Many of the interesting aspects of Bézier patches can not be appreciated with only one patch; therefore the applet allows users to work with two patches simultaneously. These patches share four end-points and consequently have end-to-end continuity, but are otherwise treated as two separate entities. The patches will not necessarily form a smooth surface, so the applet allows them to be connected. When connected, the applet takes control of the four shared points and positions them to obtain a smooth transition. The differences between separate and connected patches provide a good feel for how Bézier patches can be used to model real-life surfaces.
Flat shading - Wire-frame models are easy to draw and provide a good feel for a surface's shape, but are not always sufficient for visualization purposes. To provide a better idea of what the patch looks like, the applet can draw filled polygons. To give users the necessary depth cues, these polygons can be colored by two schemes: gradient shading and contour shading. Gradient shading illuminates polygons by a virtual light positioned directly over the patch. Polygons are shaded according to their orientation with respect to the light source: polygons directly hit by light are bright, while those at an angle to the light's rays are dimmer. Contour shading colors the polygons of the patch according to their heights: polygons having the same height are given the same color. Contour shading is ideal for determining the relative heights of polygons from separate areas of the patch. The color differences created by the two schemes allow users to get an even better feel for the patch's shape.
Painter's algorithm - Normally, hidden-surface removal is a complex task that requires the use of a Z-buffer or ray-tracing techniques. By taking advantage of the Bézier patch's shape, the applet is able to use the painter's algorithm to draw polygons quickly. The painter's algorithm draws distant objects before closer ones, thus ensuring things that should be blocked from view are, as well as allowing glimpses of distant objects when possible. The use of this algorithm gives the benefits of hidden-surface removal with very few of the complexity issues.

Conclusion
Writing this applet was a good learning experience. It uses a number of three-dimensional graphics principles and takes advantage of many of Java's features. I am pleased with the applet's performance and feel that it is easy for users to understand. Most importantly, I feel that this applet demonstrates the properties of Bézier patches in a way that is both informative and fun to explore.


The applet is available.