Java Geometry Algorithm parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2)

Here you can find the source of parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2)

Description

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

License

Open Source License

Parameter

Parameter Description
coefficients the Coefficients
startPoint the Start Point
endPoint the End Point
controlPoint1 the First Control Point
controlPoint2 the Second Control Point
padding the area surrounding the curve

Declaration

static void parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1,
        Point controlPoint2) 

Method Source Code


//package com.java2s;
/*// ww  w .j  a  va 2s .  c  o 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.
 *
 */

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));

    }
}

Related

  1. nearestColinearPoint(final Line2D segment, final Point2D point)
  2. nearestPointOnLine(Line2D l, Point2D p, boolean clampToSegment, Point2D dest)
  3. newZeroPoint()
  4. oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB)
  5. parabolaByFocusAndDirectrix(Point2D.Double focus, double directrix)
  6. perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)
  7. perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)
  8. plotBezier(GeneralPath path, @Nonnull Point2D p0, @Nonnull Point2D p1, @Nonnull Point2D p2, @Nonnull Point2D p3, int depth, double displacement)
  9. plus(Point point1, Point point2)