用java画三次曲线

package 绘制图形;
//画三次曲线 cubic(立方的) curve(曲线)
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.geom.CubicCurve2D;

import javax.swing.JFrame;
import javax.swing.JPanel;



public class drawCubicCurve extends JFrame{
    public static void main(String args[]){
    new drawCubicCurve();   
    }
    public drawCubicCurve() {
        // TODO Auto-generated constructor stub
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screen = kit.getScreenSize();
        int width = screen.width;
        int hight = screen.height;
        add(new DrawCubicCurvePanel());
        setTitle("画三次曲线");
        setVisible(true);
        setBounds(width/4, hight/4, 500, 400);
        setDefaultCloseOperation(3);
    }

}
class DrawCubicCurvePanel extends JPanel{
    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
//      坐标分别代表起始坐标,第一个控制点坐标,第二个控制点坐标,终点坐标
//不太理解坐标负数以什么为基准的,只知道是负数才能产生向上的凸线
        CubicCurve2D.Double cubicCurve = new CubicCurve2D.Double(60,80,140,-140,140,300,220,80);
        g2.draw(cubicCurve);
    }
}

用java画三次曲线_第1张图片
画三次曲线.png

画二次曲线

你可能感兴趣的:(用java画三次曲线)