How to Create Bezier Curve Animation Using Java Applet?
An applet is a Java program that can be embedded into a web page. Applets are small Java applications that can be accessed on an Internet server, and transported over the Internet. Before getting into it let’s check some software requirements
- Java SE Development Kit 8u361 by Oracle
- To Download JDK 8 Click Here.
Note: It is recommended to run the below java applet program.
Bezier Curve is a mathematically defined curve used in two-dimensional graphic applications like adobe Illustrator, Inkscape, etc. The curve is defined by four points: the initial position and the terminating position i.e P0 and P3 respectively (which are called “anchors”) and two separate middle points i.e P1 and P2(which are called “handles”) in our example. Bezier curves are frequently used in computer graphics, animation, modeling, etc. A sample video is given below to get an idea how Bezier Curve looks like.
Step by Step Implementation
To generate the Bezier curve we need four Control points P0, P1, P2, and P3. This configuration is called the Cubic Bezier Curve
Step 1: Linearly interpolate between each successive pair of points based on t.
- PAB = (1 – t) * PA + t * PB
- PBC = (1 – t) * PB + t * PC
- PCD = (1 – t) * PC + t * PD
Step 2: Expanding the Above Equation
For Point AB:
- ABX = (1 – t) * AX + t * BX
- ABY = (1 – t) * AY + t * BY
For Point BC:
- BCX = (1 – t) * BX + t * CX
- BCY = (1 – t) * BY + t * CY
For Point CD:
- CDX = (1 – t) * CX + t * DX
- CDY = (1 – t) * CY + t * DY
Step 3: Linearly interpolate between each successive pair of the new points
- PABC = (1 – t) * PAB + t * PBC
- PBCD = (1 – t) * PBC + t * PCD
Step 4: Linearly interpolate between each successive pair of the new points
- TX = (1 – t) * 3 * AX + 3 * (1 – t) * 2 * t * BX + 3 * (1 – t) * t2 * CX + t3 *DX
- TY = (1 – t) * 3 * AY + 3 * (1 – t) * 2 * t * BY + 3 * (1 – t) * t2 * CY + t3 *DY
Step 5: Implementing it in Program
Please Login to comment...