AWT QuadCurve2D Class

Advertisements


Introduction

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

Class declaration

Following is the declaration for java.awt.geom.QuadCurve2D class:

public abstract class QuadCurve2D
   extends Object
      implements Shape, Cloneable

Class constructors

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

Class methods

S.N.Method & Description
1Object clone()
Creates a new object of the same class and with the same contents 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 getCtrlPt()
Returns the control point.
8abstract double getCtrlX()
Returns the X coordinate of the control point in double precision.
9abstract double getCtrlY()
Returns the Y coordinate of the control point in double precision.
10doublegetFlatness()
Returns the flatness, or maximum distance of a control point from the line connecting the end points, of this QuadCurve2D.
11static double getFlatness(double[] coords, int offset)
Returns the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the control points stored in the indicated array at the indicated index.
12static double getFlatness(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Returns the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the indicated control points.
13double getFlatnessSq()
Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of this QuadCurve2D.
14static double getFlatnessSq(double[] coords, int offset)
Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the control points stored in the indicated array at the indicated index.
15static double getFlatnessSq(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Returns the square of the flatness, or maximum distance of a control point from the line connecting the end points, of the quadratic curve specified by the indicated control points.
16abstract Point2D getP1()
Returns the start point.
17abstract Point2D getP2()
Returns the end point.
18PathIterator getPathIterator(AffineTransform at)
Returns an iteration object that defines the boundary of the shape of this QuadCurve2D.
19PathIterator getPathIterator(AffineTransform at, double flatness)
Returns an iteration object that defines the boundary of the flattened shape of this QuadCurve2D.
20abstract double getX1()
Returns the X coordinate of the start point in double in precision.
21abstract double getX2()
Returns the X coordinate of the end point in double precision.
22abstract double getY1()
Returns the Y coordinate of the start point in double precision.
23abstract double getY2()
Returns the Y coordinate of the end point in double precision.
24boolean intersects(double x, double y, double w, double h)
Tests if the interior of the Shape intersects the interior of a specified rectangular area.
25boolean intersects(Rectangle2D r)
Tests if the interior of the Shape intersects the interior of a specified Rectangle2D.
26void setCurve(double[] coords, int offset)
Sets the location of the end points and control points of this QuadCurve2D to the double coordinates at the specified offset in the specified array.
27abstract void setCurve(double x1, double y1, double ctrlx, double ctrly, double x2, double y2)
Sets the location of the end points and control point of this curve to the specified double coordinates.
28void setCurve(Point2D[] pts, int offset)
Sets the location of the end points and control points of this QuadCurve2D to the coordinates of the Point2D objects at the specified offset in the specified array.
29void setCurve(Point2D p1, Point2D cp, Point2D p2)
Sets the location of the end points and control point of this QuadCurve2D to the specified Point2D coordinates.
30void setCurve(QuadCurve2D c)
Sets the location of the end points and control point of this QuadCurve2D to the same as those in the specified QuadCurve2D.
31static int solveQuadratic(double[] eqn)
Solves the quadratic whose coefficients are in the eqn array and places the non-complex roots back into the same array, returning the number of roots.
32static int solveQuadratic(double[] eqn, double[] res)
Solves the quadratic whose coefficients are in the eqn array and places the non-complex roots into the res array, returning the number of roots.
33static void subdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff)
Subdivides the quadratic curve specified by the coordinates stored in the src array at indices srcoff through srcoff + 5 and stores the resulting two subdivided curves into the two result arrays at the corresponding indices.
34void subdivide(QuadCurve2D left, QuadCurve2D right)
Subdivides this QuadCurve2D and stores the resulting two subdivided curves into the left and right curve parameters.
35static void subdivide(QuadCurve2D src, QuadCurve2D left, QuadCurve2D right)
Subdivides the quadratic curve specified by the src parameter and stores the resulting two subdivided curves into the left and right curve parameters.

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object

QuadCurve2D Example

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

AWTGraphicsDemo
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) {
      QuadCurve2D shape = new QuadCurve2D.Double();
      shape.setCurve(250D,250D,100D,100D,200D,150D);  
      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("QuadCurve2D.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

AWT QuadCurve2D

Advertisements
Advertisements