AWT CubicCurve2D 類



簡介

CubicCurve2D 類定義了 (x,y) 座標空間中的三次引數曲線段。

類宣告

以下是java.awt.geom.CubicCurve2D類的宣告

public abstract class CubicCurve2D
   extends Object
      implements Shape, Cloneable

類建構函式

序號建構函式 & 描述
1protected CubicCurve2D()

這是一個抽象類,不能直接例項化。

類方法

序號方法 & 描述
1

Object clone()

建立一個與該物件相同類的新物件。

2

boolean contains(double x, double y)

測試指定的座標是否在 Shape 的邊界內。

3

boolean contains(double x, double y, double w, double h)

測試 Shape 的內部是否完全包含指定的矩形區域。

4

boolean contains(Point2D p)

測試指定的 Point2D 是否在 Shape 的邊界內。

5

boolean contains(Rectangle2D r)

測試 Shape 的內部是否完全包含指定的 Rectangle2D。

6

Rectangle getBounds()

返回一個完全包圍 Shape 的整數 Rectangle。

7

abstract Point2D getCtrlP1()

返回第一個控制點。

8

abstract Point2D getCtrlP2()

返回第二個控制點。

9

abstract double getCtrlX1()

以雙精度返回第一個控制點的 X 座標。

10

abstract double getCtrlX2()

以雙精度返回第二個控制點的 X 座標。

11

abstract double getCtrlY1()

以雙精度返回第一個控制點的 Y 座標。

12

abstract double getCtrlY2()

以雙精度返回第二個控制點的 Y 座標。

13

double getFlatness()

返回此曲線的平坦度。

14

static double getFlatness(double[] coords, int offset)

返回由在指定索引處指定陣列中儲存的控制點指定的立方曲線的平坦度。

15

static double getFlatness(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)

返回由指定的控制點指定的立方曲線的平坦度。

16

double getFlatnessSq()

返回此曲線的平坦度的平方。

17

static double getFlatnessSq(double[] coords, int offset)

返回由在指定索引處指定陣列中儲存的控制點指定的立方曲線的平坦度的平方。

18

static double getFlatnessSq(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)

返回由指定的控制點指定的立方曲線的平坦度的平方。

19

abstract Point2D getP1()

返回起點。

20

abstract Point2D getP2()

返回終點。

21

PathIterator getPathIterator(AffineTransform at)

返回一個迭代器物件,該物件定義形狀的邊界。

22

PathIterator getPathIterator(AffineTransform at, double flatness)

返回一個迭代器物件,該物件定義扁平化形狀的邊界。

23

abstract double getX1()

以雙精度返回起點的 X 座標。

24

abstract double getX2()

以雙精度返回終點的 X 座標。

25

abstract double getY1()

以雙精度返回起點的 Y 座標。

26

abstract double getY2()

以雙精度返回終點的 Y 座標。

27

boolean intersects(double x, double y, double w, double h)

測試 Shape 的內部是否與指定的矩形區域的內部相交。

28

boolean intersects(Rectangle2D r)

測試 Shape 的內部是否與指定的 Rectangle2D 的內部相交。

29

void setCurve(CubicCurve2D c)

將此曲線的端點和控制點的位置設定為與指定的 CubicCurve2D 中的位置相同。

30

void setCurve(double[] coords, int offset)

將此曲線的端點和控制點的位置設定為指定陣列中指定偏移量處的雙精度座標。

31abstract void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2)

將此曲線的端點和控制點的位置設定為指定的雙精度座標。

32

void setCurve(Point2D[] pts, int offset)

將此曲線的端點和控制點的位置設定為指定陣列中指定偏移量處 Point2D 物件的座標。

33

void setCurve(Point2D p1, Point2D cp1, Point2D cp2, Point2D p2)

將此曲線的端點和控制點的位置設定為指定的 Point2D 座標。

34

static int solveCubic(double[] eqn)

求解係數在 eqn 陣列中的三次方程,並將非複數根放回同一陣列中,返回根的數量。

35

static int solveCubic(double[] eqn, double[] res)

求解係數在 eqn 陣列中的三次方程,並將非複數根放入 res 陣列中,返回根的數量。

36

void subdivide(CubicCurve2D left, CubicCurve2D right)

細分此三次曲線並將生成的兩個細分曲線儲存到左曲線和右曲線引數中。

37

static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right)

細分由 src 引數指定的立方曲線並將生成的兩個細分曲線儲存到左曲線和右曲線引數中。

38

static void subdivide(double[] src, int srcoff, double[] left, int leftoff, double[] right, int rightoff)

細分由 src 陣列中從 srcoff 到 (srcoff + 7) 的索引儲存的座標指定的立方曲線,並將生成的兩個細分曲線儲存到兩個結果陣列中的相應索引處。

繼承的方法

此類繼承自以下類的方法

  • java.lang.Object

CubicCurve2D 示例

使用您選擇的任何編輯器建立以下 Java 程式,例如在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);
   }
}

使用命令提示符編譯程式。轉到D:/ > AWT

並鍵入以下命令。

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

如果沒有錯誤,則表示編譯成功。使用以下命令執行程式。

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

驗證以下輸出

AWT CubicCurve2D
awt_graphics.htm
廣告
© . All rights reserved.