Java examples for java.lang:Math Operation
Given a endpoints and control points, compute the coefficients to trace out the curve as p(t) = c[0] + c[1]*t + c[2]*t^2 + c[3]*t^3
/*/*from w w w . ja va 2 s . co m*/ * Twirl Editor - Petri-Net Editor * * Copyright (C) 2009 Neil Brittliff * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * */ //package com.java2s; import java.awt.Point; public class Main { /** * Given a curveto's endpoints and control points, compute the coefficients * to trace out the curve as p(t) = c[0] + c[1]*t + c[2]*t^2 + c[3]*t^3 * * @param coefficients * the Coefficients * @param startPoint * the Start Point * @param endPoint * the End Point * @param controlPoint1 * the First Control Point * @param controlPoint2 * the Second Control Point * @param padding * the area surrounding the curve * */ static void parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2) { Point tangent2 = new Point(); tangent2.x = (int) (3.0 * (endPoint.x - controlPoint2.x)); tangent2.y = (int) (3.0 * (endPoint.y - controlPoint2.y)); coefficients[0] = startPoint; coefficients[1] = new Point( (int) (3.0 * (controlPoint1.x - startPoint.x)), (int) (3.0 * (controlPoint1.y - startPoint.y))); // tangent coefficients[2] = new Point( (int) (3.0 * (endPoint.x - startPoint.x) - 2.0 * coefficients[1].x - tangent2.x), (int) (3.0 * (endPoint.y - startPoint.y) - 2.0 * coefficients[1].y - tangent2.y)); coefficients[3] = new Point( (int) (2.0 * (startPoint.x - endPoint.x) + coefficients[1].x + tangent2.x), (int) (2.0 * (startPoint.y - endPoint.y) + coefficients[1].y + tangent2.y)); } }