Example usage for java.awt.geom Point2D.Double setLocation

List of usage examples for java.awt.geom Point2D.Double setLocation

Introduction

In this page you can find the example usage for java.awt.geom Point2D.Double setLocation.

Prototype

public void setLocation(Point2D p) 

Source Link

Document

Sets the location of this Point2D to the same coordinates as the specified Point2D object.

Usage

From source file:ChartUsingJava.XYSmoothLineAndShapeRenderer.java

/**
 * Updates the control points./*from   w w  w.j  a v a 2s.  co  m*/
 *
 * @param point0
 * @param point1
 * @param point2
 * @param point3
 * @param control1
 * @param control2
 * @param smooth
 */
public static void getControlPoints(Point2D.Double point0, Point2D.Double point1, Point2D.Double point2,
        Point2D.Double point3, Point2D.Double control1, Point2D.Double control2, double smooth) {

    // Reference: http://www.antigrain.com/research/bezier_interpolation/

    if (point0 == null)
        point0 = point1; //new Point2D.Double(0, 0);
    if (point3 == null)
        point3 = point2; //new Point2D.Double(0, 0);

    Point2D.Double c1 = new Point2D.Double((point0.x + point1.x) / 2.0, (point0.y + point1.y) / 2.0);
    Point2D.Double c2 = new Point2D.Double((point1.x + point2.x) / 2.0, (point1.y + point2.y) / 2.0);
    Point2D.Double c3 = new Point2D.Double((point2.x + point3.x) / 2.0, (point2.y + point3.y) / 2.0);

    double len1 = point1.distance(point0);
    double len2 = point2.distance(point1);
    double len3 = point3.distance(point2);

    double k1 = len1 / (len1 + len2);
    double k2 = len2 / (len2 + len3);

    Point2D.Double m1 = new Point2D.Double(c1.x + (c2.x - c1.x) * k1, c1.y + (c2.y - c1.y) * k1);
    Point2D.Double m2 = new Point2D.Double(c2.x + (c3.x - c2.x) * k2, c2.y + (c3.y - c2.y) * k2);

    control1.setLocation(new Point2D.Double(m1.x + (c2.x - m1.x) * smooth + point1.x - m1.x,
            m1.y + (c2.y - m1.y) * smooth + point1.y - m1.y));
    control2.setLocation(new Point2D.Double(m2.x + (c2.x - m2.x) * smooth + point2.x - m2.x,
            m2.y + (c2.y - m2.y) * smooth + point2.y - m2.y));
}

From source file:org.jfree.experimental.chart.renderer.xy.XYSmoothLineAndShapeRenderer.java

/**
 * Updates the control points.//  w  w w . j a  v a 2 s .c  om
 *
 * @param point0
 * @param point1
 * @param point2
 * @param point3
 * @param control1
 * @param control2
 * @param smooth
 */
public static void getControlPoints(Point2D.Double point0, Point2D.Double point1, Point2D.Double point2,
        Point2D.Double point3, Point2D.Double control1, Point2D.Double control2, double smooth) {

    // Reference: http://www.antigrain.com/research/bezier_interpolation/

    if (point0 == null) {
        point0 = point1;
    } //new Point2D.Double(0, 0);
    if (point3 == null) {
        point3 = point2;
    } //new Point2D.Double(0, 0);

    Point2D.Double c1 = new Point2D.Double((point0.x + point1.x) / 2.0, (point0.y + point1.y) / 2.0);
    Point2D.Double c2 = new Point2D.Double((point1.x + point2.x) / 2.0, (point1.y + point2.y) / 2.0);
    Point2D.Double c3 = new Point2D.Double((point2.x + point3.x) / 2.0, (point2.y + point3.y) / 2.0);

    double len1 = point1.distance(point0);
    double len2 = point2.distance(point1);
    double len3 = point3.distance(point2);

    double k1 = len1 / (len1 + len2);
    double k2 = len2 / (len2 + len3);

    Point2D.Double m1 = new Point2D.Double(c1.x + (c2.x - c1.x) * k1, c1.y + (c2.y - c1.y) * k1);
    Point2D.Double m2 = new Point2D.Double(c2.x + (c3.x - c2.x) * k2, c2.y + (c3.y - c2.y) * k2);

    control1.setLocation(new Point2D.Double(m1.x + (c2.x - m1.x) * smooth + point1.x - m1.x,
            m1.y + (c2.y - m1.y) * smooth + point1.y - m1.y));
    control2.setLocation(new Point2D.Double(m2.x + (c2.x - m2.x) * smooth + point2.x - m2.x,
            m2.y + (c2.y - m2.y) * smooth + point2.y - m2.y));
}