Java Geometry Algorithm applyMidPointApprox(CubicCurve2D cubic, QuadCurve2D quad)

Here you can find the source of applyMidPointApprox(CubicCurve2D cubic, QuadCurve2D quad)

Description

Converts a cubic B&eacute;zier to a quadratic one, using the <a href="http://www.caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html#mid-point-approx">mid-point approximation</a>

License

Open Source License

Parameter

Parameter Description
cubic the cubic
quad the approximating quadratic.

Declaration

static final private void applyMidPointApprox(CubicCurve2D cubic, QuadCurve2D quad) 

Method Source Code


//package com.java2s;
/*//  w ww . j  a va2s  . co  m
  Copyright (c) 2006 Adrian Colomitchi
    
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without 
  restriction, including without limitation the rights to use, 
  copy, modify, merge, publish, distribute, sublicense, and/or 
  sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following 
  conditions:
    
  The above copyright notice and this permission notice 
  shall be included in all copies or substantial portions
  of the Software.
    
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
  ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
 */

import java.awt.geom.CubicCurve2D;

import java.awt.geom.QuadCurve2D;

public class Main {
    /**
     * Converts a cubic B&eacute;zier to a quadratic one, using the
     * <a href="http://www.caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html#mid-point-approx">mid-point
     * approximation</a>
     * @param cubic the cubic
     * @param quad the approximating quadratic.
     */
    static final private void applyMidPointApprox(CubicCurve2D cubic, QuadCurve2D quad) {
        double a0x = cubic.getX1(), a0y = cubic.getY1();
        double a1x = cubic.getX2(), a1y = cubic.getY2();
        double p0x = (3 * cubic.getCtrlX1() - a0x) / 2.0;
        double p0y = (3 * cubic.getCtrlY1() - a0y) / 2.0;
        double p1x = (3 * cubic.getCtrlX2() - a1x) / 2.0;
        double p1y = (3 * cubic.getCtrlY2() - a1y) / 2.0;
        quad.setCurve(a0x, a0y, (p0x + p1x) / 2, (p0y + p1y) / 2, a1x, a1y);
    }
}

Related

  1. absoluteBearing(Point2D source, Point2D target)
  2. absoluteBearing(Point2D.Double sourceLocation, Point2D.Double target)
  3. applyCoG(Point2D.Double[] points, Point2D.Double cog)
  4. applyDynamism(final Point[] spline, final int msForMove, final int msPerMove)
  5. arcThroughThreePoints(float x1, float y1, float x2, float y2, float x3, float y3, boolean clockwise)
  6. area2(Point2D a, Point2D b, Point2D c)
  7. AreAlign(Point2D.Double pivot, Point2D.Double a, Point2D.Double b)
  8. areDifferentAnchorPoints(Point2D p1, Point2D p2)