Instructions for "bezier2.class"

Samuel Dagan

Last Update: 2 August 2008



Copyright notice

Copyright © 2002 Samuel Dagan.

The original directory "http://alzt.tau.ac.il/~dagan/tools/Bezier2/" contains open source software intended for people interested in using SVG for graphic display of curves expressed mathematically. SVG - scalable vectors graphics is recommended as the standard for the internet by the WWW consortium. The software could be studied, used, modified and distributed for any none commercial purpose as long as the present copyright notice is kept and retained unchanged.


Contents of the directory

The original directory contains the following files:


General information

The software is based on the Java™ language and the quadratic Bezier-Casteljau method for convenient expression of curves in two dimensions. A finite curve provided by the user is approximated in number of intervals as quadratic expressions. Each of these intervals consists of the two end points and one control point, as requested by a path of SVG. The number of intervals is automatically obtained by the required error limit. Care is taken that the derivative of the obtained approximation is a continuous function and that the approximated curve do not deviate from the original by more than this error limit. An example is provided in order to help the user. The program uses double precision floating point numbers.


Requirements


Downloading

Just open the directory and save all the files in one directory of yours (34.7 KB). See "Contents of the directory" - above.


Running the program

The user should run "bezier2.class" and provide on the command line five parameters:

The curve to be parameterized as a Bezier path is supplied by the user as a separate class that should contain the following methods:

As an example the "sinus" class is provided here for parameterization of sin(x), where the end points should be between zero and π/2.

The class "curve" is dummy and serves only to extend the class of the curve, in the example here - the "sinus.class". The user should not forget to make the appropriate change and recompile "curve.class" for a different curve.

The printed output actually gives all the necessary information of the run. An additional output is written out on a file called "tempor.txt" which contains the required SVG path. If the file does not exist - it is created, otherwise the output is appended. In order to avoid output of unnecessary insignificant digits, a default formatter of the form ####.###### is used for the output (printed and written). If the user does not want the formater, but wishes to have the full display of the numbers he can turn it off for the written output, by adding a sixth parameter on the command line in the form of a string starting with "n" or "N" (for no).

The "tempor.txt" file in the original directory was obtained by running "bezier2.class" with end points of sinus: 0 0 1.570796 1 (4 parameters) and an error of 0.0005. The meaning of the error is that for a display of the sinus with the scale of 1000 pixels per one unit, the error is 0.5 pixels.

The "sinus.svg" displays the sin(x) interval -π/2 < x < 5π/2 and was obtained by simple transformations of the path from "tempor.txt".


The algorithm used in the program

For people interested in the algorithm used by the program, here are some details. The program starts by building a quadratic Bezier-Casteljau control point pc=(xc,yc) based on the intersection of the two tangents of the curve drawn from the end points p1=(x1,y1) and p2=(x2,y2). The tangents themselves are obtained from the known derivatives. The mid point pm=(p1+p2+2*pc)/4, corresponding to the quadratic Bezier curve with mid value of the parameter t=1/2 is used as a test point. If the curve was really a quadratic Bezier, this point should lie on the curve and his derivative should be equal to (y2-y1)/(x2-x1). The point of the real curve pr with this same derivative is calculated and compared to the test point pm. If the distance between them is smaller than the required error limit, it means that the parameterization was found and the program exits.

If the curve is not quadratic, it cannot be parameterized just with one control point. In such case after the previous stage they are two intervals with known end points and derivatives. The procedure is repeated for each interval separately and occasionally they could be subdivided in smaller intervals. The program continues on, till the needed accuracy is achieved.


Technical information about the example


Bugs and suggestions

If you find a bug or have any suggestion for improving the program please contact me.