## 介绍

The CubicCurve2D class states a cubic parametric curve segment in (x,y) coordinate space.

## 类声明

Following is the declaration for java.awt.geom.CubicCurve2Dclass:

public abstract class CubicCurve2D   extends Object      implements Shape, Cloneable

## 类的构造函数

S.N.Constructor & Description
1protected CubicCurve2D() This is an abstract class that cannot be instantiated directly.

## 类方法

S.N.Method & Description
1Object clone() Creates a new object of the same class as this object.
2boolean contains(double x, double y) Tests if the specified coordinates are inside the boundary of the Shape.
3boolean contains(double x, double y, double w, double h) Tests if the interior of the Shape entirely contains the specified rectangular area.
4boolean contains(Point2D p) Tests if a specified Point2D is inside the boundary of the Shape.
5boolean contains(Rectangle2D r) Tests if the interior of the Shape entirely contains the specified Rectangle2D.
6Rectangle getBounds() Returns an integer Rectangle that completely encloses the Shape.
7abstract Point2D getCtrlP1() Returns the first control point.
8abstract Point2D getCtrlP2() Returns the second control point.
9abstract double getCtrlX1() Returns the X coordinate of the first control point in double precision.
10abstract double getCtrlX2() Returns the X coordinate of the second control point in double precision.
11abstract double getCtrlY1() Returns the Y coordinate of the first control point in double precision.
12abstract double getCtrlY2() Returns the Y coordinate of the second control point in double precision.
13double getFlatness() Returns the flatness of this curve.
14static double getFlatness(double[] coords, int offset) Returns the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index.
15static double getFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Returns the flatness of the cubic curve specified by the indicated control points.
16double getFlatnessSq() Returns the square of the flatness of this curve.
17static double getFlatnessSq(double[] coords, int offset) Returns the square of the flatness of the cubic curve specified by the control points stored in the indicated array at the indicated index.
18static double getFlatnessSq(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Returns the square of the flatness of the cubic curve specified by the indicated control points.
19abstract Point2D getP1() Returns the start point.
20abstract Point2D getP2() Returns the end point.
21PathIterator getPathIterator(AffineTransform at) Returns an iteration object that defines the boundary of the shape.
22PathIterator getPathIterator(AffineTransform at, double flatness) Return an iteration object that defines the boundary of the flattened shape.
23abstract double getX1() Returns the X coordinate of the start point in double precision.
24abstract double getX2() Returns the X coordinate of the end point in double precision.
25abstract double getY1() Returns the Y coordinate of the start point in double precision.
26abstract double getY2() Returns the Y coordinate of the end point in double precision.
27boolean intersects(double x, double y, double w, double h) Tests if the interior of the Shape intersects the interior of a specified rectangular area.
28boolean intersects(Rectangle2D r) Tests if the interior of the Shape intersects the interior of a specified Rectangle2D.
29void setCurve(CubicCurve2D c) Sets the location of the end points and control points of this curve to the same as those in the specified CubicCurve2D.
30void setCurve(double[] coords, int offset) Sets the location of the end points and control points of this curve to the double coordinates at the specified offset in the specified array.
31abstract void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) Sets the location of the end points and control points of this curve to the specified double coordinates.
32void setCurve(Point2D[] pts, int offset) Sets the location of the end points and control points of this curve to the coordinates of the Point2D objects at the specified offset in the specified array.
33void setCurve(Point2D p1, Point2D cp1, Point2D cp2, Point2D p2) Sets the location of the end points and control points of this curve to the specified Point2D coordinates.
34static int solveCubic(double[] eqn) Solves the cubic whose coefficients are in the eqn array and places the non-complex roots back into the same array, returning the number of roots.
35static int solveCubic(double[] eqn, double[] res) Solve the cubic whose coefficients are in the eqn array and place the non-complex roots into the res array, returning the number of roots.
36void subdivide(CubicCurve2D left, CubicCurve2D right) Subdivides this cubic curve and stores the resulting two subdivided curves into the left and right curve parameters.
37static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right)Subdivides the cubic curve specified by the src parameter and stores the resulting two subdivided curves into the left and right curve parameters.
38static void subdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff) Subdivides the cubic curve specified by the coordinates stored in the src array at indices srcoff through (srcoff + 7) and stores the resulting two subdivided curves into the two result arrays at the corresponding indices.

## 方法继承

This class inherits methods from the following classes:

• java.lang.Object

## CubicCurve2D Example

Create the following java program using any editor of your choice in say D:/ > AWT > com > tutorialspoint > gui >AWTGraphicsDemo.java

package com.tutorialspoint.gui; import java.awt.*;import java.awt.event.*;import java.awt.geom.*; public class AWTGraphicsDemo extends Frame {    public AWTGraphicsDemo(){      super("Java AWT Examples");      prepareGUI();   }    public static void main(String[] args){      AWTGraphicsDemo  awtGraphicsDemo = new AWTGraphicsDemo();        awtGraphicsDemo.setVisible(true);   }    private void prepareGUI(){      setSize(400,400);      addWindowListener(new WindowAdapter() {         public void windowClosing(WindowEvent windowEvent){            System.exit(0);         }              });    }        @Override   public void paint(Graphics g) {      CubicCurve2D shape = new CubicCurve2D.Float();      shape.setCurve(250F,250F,20F,90F,140F,100F,350F,330F);             Graphics2D g2 = (Graphics2D) g;       g2.draw (shape);      Font font = new Font("Serif", Font.PLAIN, 24);      g2.setFont(font);      g.drawString("Welcome to TutorialsPoint", 50, 70);      g2.drawString("CubicCurve2D.Curve", 100, 120);   }}

Compile the program using command prompt. Go to D:/ > AWT and type the following command.

D:\AWT>javac com\tutorialspoint\gui\AWTGraphicsDemo.java

If no error comes that means compilation is successful. Run the program using following command.

D:\AWT>java com.tutorialspoint.gui.AWTGraphicsDemo

Verify the following output