Last Update: 2 August 2008

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.

The original directory contains the following files:

**The present**"readMe.html"**Three classes:****Their souce files****An output sample**"tempor.txt"**SVG graphics sample**"sinus.svg"

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.

- The finite curve supplied by the user should not contain more than one point corresponding to the same derivative. If not the curve should be divided in parts.
- The user should be able to provide the derivatives at the end points of the curve and also to calculate the point on the curve corresponding to any value of the derivative.
- The user should have an elementary knowledge of Java™ programming. He needs also the appropriate SDK (JDK) installed on his machine.
- The user should have an elementary knowledge of SVG and should be able to display SVG graphics (see references).

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

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

- The two end points of the curve (x1 y1 x2 y2).
- The maximal error required (absolute).
- There is a sixth, optional parameter, which is explained further.

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

- void initiate(double error); // initiates the curve, stores the error, prints. It can be dummy.
- boolean validate(double x, double y); // validates if (x,y) is a valid end-point of the curve. It can be dummy by just returning the value: true.
- double derivate(double x, double y); // returns dy/dx at the end-point(x,y). It could be also infinite.
- double[2] realpnt(double derivative); // returns point(x,y) of the curve corresponding to dy/dx.

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".

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

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.

- The run was performed under "Windows™ 2000 Professional".
- The "Java™2 SDK1.4" was used for compilation and running.
- The "sinus.svg" was tested first (in 2003) with "Adobe™ SVG
Viewer vs 3.0", and later (in 2008) with native SVG supporting browsers: Opera and Firefox.

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