Java examples for 2D Graphics:Curve
Gets a Point2D on the given QuadCurve2D at the parameterized position t.
/*/*from ww w .j a v a 2 s.c o m*/ * Copyright (C) 2005 Jordan Kiang * jordan-at-kiang.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //package com.java2s; import java.awt.geom.Point2D; import java.awt.geom.QuadCurve2D; public class Main { /** * Gets a Point2D on the given QuadCurve2D at the parameterized position t. * * @param curve the curve * @param t a parameterized t value along the length of the curve, 0-1 inclusive * @return the point */ static public Point2D getPointOnQuadCurve(QuadCurve2D curve, double t) { if (null == curve) { throw new NullPointerException("curve must be non-null!"); } else if (t < 0.0 || t > 1.0) { throw new IllegalArgumentException("t must be between 0 and 1!"); } double ax = getQuadAx(curve); double bx = getQuadBx(curve); double ay = getQuadAy(curve); double by = getQuadBy(curve); double tSquared = t * t; double x = (ax * tSquared) + (bx * t) + curve.getX1(); double y = (ay * tSquared) + (by * t) + curve.getY1(); return new Point2D.Double(x, y); } static private double getQuadAx(QuadCurve2D curve) { return curve.getX1() - (2.0 * curve.getCtrlX()) + curve.getX2(); } static private double getQuadBx(QuadCurve2D curve) { return 2.0 * (-curve.getX1() + curve.getCtrlX()); } static private double getQuadAy(QuadCurve2D curve) { return curve.getY1() - (2.0 * curve.getCtrlY()) + curve.getY2(); } static private double getQuadBy(QuadCurve2D curve) { return 2.0 * (-curve.getY1() + curve.getCtrlY()); } }