Here you can find the source of applyMidPointApprox(CubicCurve2D cubic, QuadCurve2D quad)
Converts a cubic Bé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>
Parameter | Description |
---|---|
cubic | the cubic |
quad | the approximating quadratic. |
static final private void applyMidPointApprox(CubicCurve2D cubic, QuadCurve2D quad)
//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é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); } }