下面列出了java.awt.geom.CubicCurve2D#getY2 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
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();
}
/**
* 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;
}
/**
* Report the left-to-right Bézier curve which best approximates the slur.
* <p>
* It is built by combining the left half (point & control point) of left circle curve and
* the right half (control point & 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;
}
/**
* 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);
}