Java Code Examples for java.awt.geom.CubicCurve2D#getCtrlY1()

The following examples show how to use java.awt.geom.CubicCurve2D#getCtrlY1() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Circle.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Report the half-way point on Bézier curve.
 *
 * @return the middle of the curve arc
 */
public Point2D getMiddlePoint ()
{
    CubicCurve2D c = getCurve();

    return new Point2D.Double(
            (c.getX1() + (3 * c.getCtrlX1()) + (3 * c.getCtrlX2()) + c.getX2()) / 8,
            (c.getY1() + (3 * c.getCtrlY1()) + (3 * c.getCtrlY2()) + c.getY2()) / 8);
}
 
Example 2
Source File: Jaxb.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
CubicFacade (CubicCurve2D curve)
{
    this.x1 = curve.getX1();
    this.y1 = curve.getY1();
    this.ctrlx1 = curve.getCtrlX1();
    this.ctrly1 = curve.getCtrlY1();
    this.ctrlx2 = curve.getCtrlX2();
    this.ctrly2 = curve.getCtrlY2();
    this.x2 = curve.getX2();
    this.y2 = curve.getY2();
}
 
Example 3
Source File: Slur.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Report whether the provided curve is below the notes (turned
 * upwards) or above the notes (turned downwards).
 *
 * @param curve the provided curve to check
 * @return true if below, false if above
 */
private static boolean isBelow (CubicCurve2D curve)
{
    // Determine arc orientation (above or below)
    final double DX = curve.getX2() - curve.getX1();
    final double DY = curve.getY2() - curve.getY1();
    final double power = (curve.getCtrlX1() * DY)
                         - (curve.getCtrlY1() * DX) - (curve.getX1() * DY)
                         + (curve.getY1() * DX);

    return power < 0;
}
 
Example 4
Source File: SlurInfo.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Report the left-to-right Bézier curve which best approximates the slur.
 * <p>
 * It is built by combining the left half (point &amp; control point) of left circle curve and
 * the right half (control point &amp; point) of right circle curve.
 * Vectors from point to related control point are applied a ratio extension so that curve
 * middle point (M) fits on slur middle point (M').
 * We apply the same ratio on both vectors, which may not be the best choice but that's enough
 * for a first version.
 * On a bezier curve, naming P the middle point of segment (P1,P2) and C the middle point of
 * segment (CP1,CP2), we always have vector PC = 4/3 of vector PM.
 * So, (PC' - PC) = 4/3 (PM' - PM) or (ratio - 1) * PC = 4/3 * deltaM, which gives ratio value.
 *
 * @return the bezier curve
 */
public CubicCurve2D getCurve ()
{
    if (curve == null) {
        Model leftModel = getSideModel(true);
        Model rightModel = getSideModel(false);

        if ((leftModel == null) || (rightModel == null)) {
            ///logger.warn("No side circle");
            return null;
        }

        // Assume we have circle models on both ends
        if (!(leftModel instanceof CircleModel) || !(rightModel instanceof CircleModel)) {
            return null;
        }

        CubicCurve2D left = (CubicCurve2D) leftModel.getCurve();
        CubicCurve2D right = (CubicCurve2D) rightModel.getCurve();

        if (left == right) {
            curve = left;
        } else {
            double x1 = left.getX1();
            double y1 = left.getY1();
            double cx1 = left.getCtrlX1();
            double cy1 = left.getCtrlY1();
            double cx2 = right.getCtrlX2();
            double cy2 = right.getCtrlY2();
            double x2 = right.getX2();
            double y2 = right.getY2();

            // Compute affinity ratio out of mid point translation
            Point midPt = points.get(points.size() / 2); // Approximately
            double mx = (x1 + x2 + (3 * (cx1 + cx2))) / 8;
            double my = (y1 + y2 + (3 * (cy1 + cy2))) / 8;
            double deltaM = Math.hypot(midPt.x - mx, midPt.y - my);
            double pc = Math.hypot((cx1 + cx2) - (x1 + x2), (cy1 + cy2) - (y1 + y2)) / 2;
            double ratio = 1 + ((4 * deltaM) / (3 * pc));

            // Apply ratio on vectors to control points
            curve = new CubicCurve2D.Double(
                    x1,
                    y1,
                    x1 + (ratio * (cx1 - x1)), // cx1'
                    y1 + (ratio * (cy1 - y1)), // cy1'
                    x2 + (ratio * (cx2 - x2)), // cx2'
                    y2 + (ratio * (cy2 - y2)), // cy2'
                    x2,
                    y2);
        }
    }

    return curve;
}
 
Example 5
Source File: CubicUtil.java    From audiveris with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Report the point on the curve, located at t = 1-t = 0.5.
 * It splits the curve length equally.
 * P: middle of segment P1..P2
 * C: middle of segment CP1..CP2
 * M: middle of curve
 * PM = 3/4 * PC
 *
 * @param c the provided curve
 * @return the mid point on curve
 */
public static Point2D getMidPoint (CubicCurve2D c)
{
    return new Point2D.Double(
            (c.getX1() + (3 * c.getCtrlX1()) + (3 * c.getCtrlX2()) + c.getX2()) / 8,
            (c.getY1() + (3 * c.getCtrlY1()) + (3 * c.getCtrlY2()) + c.getY2()) / 8);
}