Java Graphics Draw drawSpline(Graphics graphics, int x1, int y1, int x2, int y2, int x3, int y3)

Here you can find the source of drawSpline(Graphics graphics, int x1, int y1, int x2, int y2, int x3, int y3)

Description

draw Spline

License

Open Source License

Declaration

public static void drawSpline(Graphics graphics, int x1, int y1, int x2, int y2, int x3, int y3) 

Method Source Code


//package com.java2s;
import java.awt.*;

public class Main {
    private static final int SPLINE_THRESH = 3;

    public static void drawSpline(Graphics graphics, int x1, int y1, int x2, int y2, int x3, int y3) {
        int xa, ya, xb, yb, xc, yc, xp, yp;

        xa = (x1 + x2) / 2;//from ww  w.  j  a  v a2 s. c o  m
        ya = (y1 + y2) / 2;
        xc = (x2 + x3) / 2;
        yc = (y2 + y3) / 2;
        xb = (xa + xc) / 2;
        yb = (ya + yc) / 2;

        xp = (x1 + xb) / 2;
        yp = (y1 + yb) / 2;
        if (Math.abs(xa - xp) + Math.abs(ya - yp) > SPLINE_THRESH)
            drawSpline(graphics, x1, y1, xa, ya, xb, yb);
        else
            graphics.drawLine(x1, y1, xb, yb);

        xp = (x3 + xb) / 2;
        yp = (y3 + yb) / 2;
        if (Math.abs(xc - xp) + Math.abs(yc - yp) > SPLINE_THRESH)
            drawSpline(graphics, xb, yb, xc, yc, x3, y3);
        else
            graphics.drawLine(xb, yb, x3, y3);
    }
}

Related

  1. drawRTriangle(Graphics g, Color color, int x, int y, int r)
  2. drawScaleTick(Graphics g, int x, int y, boolean yAxisP, int length)
  3. drawScrollBar(Graphics g, int which, int direction, int x, int y, int fmWidth, int fmHeight, Color fg, Color bg)
  4. drawSelectionBox(Graphics g)
  5. drawSelectionPoint(Graphics g, Point p)
  6. drawSquarePoint(Graphics2D g2, Point2D.Double pt, int ptSize, Color color)
  7. drawStackTrace(Graphics gr, int x, int y, Throwable ex)
  8. drawStage(Graphics g, int x, int y)
  9. drawStar(Graphics g, int x, int y)