by Dinesh Thakur

CubicCurve2D which also shows the segments joining  the ends with the points control and the set together. An example of use appears in the following code, which also have highlighted the four reference points. The result can be seen in CubicCurve2D Java Example.

Following is table that lists some of the Constructors and methods of CubicCurve2D class:

Constructors and Methods

Description

CubicCurve2D.Double ()

Creates a CubicCurve2D from (0, 0) to (0, 0), with control point (0,0)

CubicCurve2D.Double (double X1, double Y1, double CX1, double CY1, double X2, double Y2)

Creates a CubicCurve2D from (X1, Y1) to (X2, Y2), with control point (CX1, CY1).

CubicCurve2D.Float ()

Creates a CubicCurve2D from (0, 0) to (0, 0), with control points (0,0).

CubicCurve2D.Float (float X1, float Y1, float CX1, float CY1, float X2, float Y2)

Creates a CubicCurve2D from (X1, Y1) to (X2, Y2), with control point (CX1, CY1).

boolean intersects (double X, double Y, double Width, double Height)

Returns true if the rectangle described by (X, Y, Width, Height) intersects the CubicCurve

void setCurve (double X1, double Y1, double CX1, double CY1, double X2, double Y2)

Sets the ends of the CubicCurve as (X1, Y1) and (X2, Y2).

Drawingan CubicCurve exampleshownthecodeas follows:

import java.applet.Applet;

import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.image.*;
public class DrawCubicCurve2DExample extends Applet {
public static void main(String[] args) {
Frame DrawCubicCurve2D = new Frame("Draw CubicCurve2D Example");
DrawCubicCurve2D.setSize(350, 250);
Applet DrawCubicCurve2DExample = new DrawCubicCurve2DExample();
DrawCubicCurve2D.add(DrawCubicCurve2DExample);
DrawCubicCurve2D.setVisible(true);
DrawCubicCurve2D.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
      }
    });
  }
  public void paint(Graphics g) {
    g.setColor(Color.blue);
    g.setFont(new Font("Arial",Font.BOLD,14));
    g.drawString("Draw CubicCurve2D Example", 50, 40);
    g.setFont(new Font("Arial",Font.BOLD,10));
    g.drawString("http://ecomputernotes.com", 200, 205);
                super.paint(g);
                Graphics2D G2D = (Graphics2D)g;
                G2D.setColor(Color.blue);
                G2D.setStroke(new BasicStroke(3.0f));
                CubicCurve2D CC2D = new CubicCurve2D.Float(40.0f, 60.0f, 60.0f, 120.0f, 140.0f, 130.0f, 150.0f, 210.0f);
                G2D.draw(CC2D);
                G2D.setColor(Color.blue);
                G2D.draw(new Rectangle2D.Float(40.0f, 60.0f, 1.0f, 1.0f));
                G2D.draw(new Rectangle2D.Float(60.0f, 120.0f, 1.0f, 1.0f));
                G2D.draw(new Rectangle2D.Float(140.0f, 130.0f, 1.0f, 1.0f));
                G2D.draw(new Rectangle2D.Float(150.0f, 210.0f, 1.0f, 1.0f));
  }
}

CubicCurve2D Java Example