android.graphics.Path#rCubicTo ( )源码实例Demo

下面列出了android.graphics.Path#rCubicTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ncalc   文件: CubicBezierCurve2D.java
public Path getGeneralPath() {
    Path path = new Path();
    path.moveTo((float) x1, (float) y1);

    path.rCubicTo((float) ctrlx1, (float) ctrly1, (float) ctrlx2, (float) ctrly2, (float) x2, (float) y2);

    return path;
}
 
源代码2 项目: ncalc   文件: EllipseArc2D.java
public Path appendPath(Path path) {
    // number of curves to approximate the arc
    int nSeg = (int) ceil(abs(angleExtent) / (PI / 2));
    nSeg = min(nSeg, 4);

    // angular extent of each curve
    double ext = angleExtent / nSeg;

    // compute coefficient
    double k = btan(abs(ext));

    for (int i = 0; i < nSeg; i++) {
        // position of the two extremities
        double ti0 = abs(i * ext);
        double ti1 = abs((i + 1) * ext);

        // extremity points
        Point2D p1 = this.point(ti0);
        Point2D p2 = this.point(ti1);

        // tangent vectors, multiplied by appropriate coefficient
        Vector2D v1 = this.tangent(ti0).times(k);
        Vector2D v2 = this.tangent(ti1).times(k);

        // append a cubic curve to the path
        path.rCubicTo((float) (p1.x() + v1.x()), (float) (p1.y() + v1.y()),
                (float) (p2.x() - v2.x()), (float) (p2.y() - v2.y()),
                (float) p2.x(), (float) p2.y());
    }
    return path;
}
 
源代码3 项目: ncalc   文件: CircleArc2D.java
public Path appendPath(Path path) {
    // number of curves to approximate the arc
    int nSeg = (int) ceil(abs(angleExtent) / (PI / 2));
    nSeg = min(nSeg, 4);

    // angular extent of each curve
    double ext = angleExtent / nSeg;

    // compute coefficient
    double k = btan(abs(ext));

    for (int i = 0; i < nSeg; i++) {
        // position of the two extremities
        double ti0 = abs(i * ext);
        double ti1 = abs((i + 1) * ext);

        // extremity points
        Point2D p1 = this.point(ti0);
        Point2D p2 = this.point(ti1);

        // tangent vectors, multiplied by appropriate coefficient
        Vector2D v1 = this.tangent(ti0).times(k);
        Vector2D v2 = this.tangent(ti1).times(k);

        // append a cubic curve to the path
        path.rCubicTo(
                (float) (p1.x() + v1.x()), (float) (p1.y() + v1.y()),
                (float) (p2.x() - v2.x()), (float) (p2.y() - v2.y()),
                (float) (p2.x()), (float) (p2.y()));
    }
    return path;
}
 
源代码4 项目: Dashchan   文件: RoundedCornersDrawable.java
@Override
public void setBounds(int left, int top, int right, int bottom) {
	Rect bounds = getBounds();
	if (bounds.left != left || bounds.top != top || bounds.right != right || bounds.bottom != bottom) {
		Path path = this.path;
		path.rewind();
		float radius = this.radius;
		float shift = ((float) Math.sqrt(2) - 1f) * radius * 4f / 3f;
		path.moveTo(left, top);
		path.rLineTo(radius, 0);
		path.rCubicTo(-shift, 0, -radius, radius - shift, -radius, radius);
		path.close();
		path.moveTo(right, top);
		path.rLineTo(-radius, 0);
		path.rCubicTo(shift, 0, radius, radius - shift, radius, radius);
		path.close();
		path.moveTo(left, bottom);
		path.rLineTo(radius, 0);
		path.rCubicTo(-shift, 0, -radius, shift - radius, -radius, -radius);
		path.close();
		path.moveTo(right, bottom);
		path.rLineTo(-radius, 0);
		path.rCubicTo(shift, 0, radius, shift - radius, radius, -radius);
		path.close();
	}
	super.setBounds(left, top, right, bottom);
}
 
源代码5 项目: VideoOS-Android-SDK   文件: SVGAPath.java
private void operate(Path finalPath, String method, StringTokenizer args) {
    float x0 = 0.0f;
    float y0 = 0.0f;
    float x1 = 0.0f;
    float y1 = 0.0f;
    float x2 = 0.0f;
    float y2 = 0.0f;
    try {
        int index = 0;
        while (args.hasMoreTokens()) {
            String s = args.nextToken();
            if (TextUtils.isEmpty(s)) {
                continue;
            }
            if (index == 0) {
                x0 = Float.valueOf(s);
            }
            if (index == 1) {
                y0 = Float.valueOf(s);
            }
            if (index == 2) {
                x1 = Float.valueOf(s);
            }
            if (index == 3) {
                y1 = Float.valueOf(s);
            }
            if (index == 4) {
                x2 = Float.valueOf(s);
            }
            if (index == 5) {
                y2 = Float.valueOf(s);
            }
            index++;
        }
    } catch (Exception e) {
    }
    SVGAPoint currentPoint = new SVGAPoint(0.0f, 0.0f, 0.0f);
    if ("M".equals(method)) {
        finalPath.moveTo(x0, y0);
        currentPoint = new SVGAPoint(x0, y0, 0.0f);
    } else if ("m".equals(method)) {
        finalPath.rMoveTo(x0, y0);
        currentPoint = new SVGAPoint(currentPoint.x + x0, currentPoint.y + y0, 0.0f);
    }
    if ("L".equals(method)) {
        finalPath.lineTo(x0, y0);
    } else if ("l".equals(method)) {
        finalPath.rLineTo(x0, y0);
    }
    if ("C".equals(method)) {
        finalPath.cubicTo(x0, y0, x1, y1, x2, y2);
    } else if ("c".equals(method)) {
        finalPath.rCubicTo(x0, y0, x1, y1, x2, y2);
    }
    if ("Q".equals(method)) {
        finalPath.quadTo(x0, y0, x1, y1);
    } else if ("q".equals(method)) {
        finalPath.rQuadTo(x0, y0, x1, y1);
    }
    if ("H".equals(method)) {
        finalPath.lineTo(x0, currentPoint.y);
    } else if ("h".equals(method)) {
        finalPath.rLineTo(x0, 0f);
    }
    if ("V".equals(method)) {
        finalPath.lineTo(currentPoint.x, x0);
    } else if ("v".equals(method)) {
        finalPath.rLineTo(0f, x0);
    }
    if ("Z".equals(method)) {
        finalPath.close();
    } else if ("z".equals(method)) {
        finalPath.close();
    }

}
 
源代码6 项目: ncalc   文件: CubicBezierCurve2D.java
public Path appendPath(Path path) {
    path.moveTo((float) x1, (float) y1);

    path.rCubicTo((float) ctrlx1, (float) ctrly1, (float) ctrlx2, (float) ctrly2, (float) x2, (float) y2);
    return path;
}
 
源代码7 项目: SVG-Android   文件: VectorPathParser.java
private static void arcToBezier(Path p,
                                double cx,
                                double cy,
                                double a,
                                double b,
                                double e1x,
                                double e1y,
                                double theta,
                                double start,
                                double sweep) {
    int numSegments = (int) Math.ceil(Math.abs(sweep * 4 / Math.PI));

    double eta1 = start;
    double cosTheta = Math.cos(theta);
    double sinTheta = Math.sin(theta);
    double cosEta1 = Math.cos(eta1);
    double sinEta1 = Math.sin(eta1);
    double ep1x = (-a * cosTheta * sinEta1) - (b * sinTheta * cosEta1);
    double ep1y = (-a * sinTheta * sinEta1) + (b * cosTheta * cosEta1);

    double anglePerSegment = sweep / numSegments;
    for (int i = 0; i < numSegments; i++) {
        double eta2 = eta1 + anglePerSegment;
        double sinEta2 = Math.sin(eta2);
        double cosEta2 = Math.cos(eta2);
        double e2x = cx + (a * cosTheta * cosEta2) - (b * sinTheta * sinEta2);
        double e2y = cy + (a * sinTheta * cosEta2) + (b * cosTheta * sinEta2);
        double ep2x = -a * cosTheta * sinEta2 - b * sinTheta * cosEta2;
        double ep2y = -a * sinTheta * sinEta2 + b * cosTheta * cosEta2;
        double tanDiff2 = Math.tan((eta2 - eta1) / 2);
        double alpha =
                Math.sin(eta2 - eta1) * (Math.sqrt(4 + (3 * tanDiff2 * tanDiff2)) - 1) / 3;
        double q1x = e1x + alpha * ep1x;
        double q1y = e1y + alpha * ep1y;
        double q2x = e2x - alpha * ep2x;
        double q2y = e2y - alpha * ep2y;

        final float delta_q1x = (float) q1x - (float) e1x;
        final float delta_q1y = (float) q1y - (float) e1y;
        final float delta_q2x = (float) q2x - (float) e1x;
        final float delta_q2y = (float) q2y - (float) e1y;
        final float delta_e2x = (float) e2x - (float) e1x;
        final float delta_e2y = (float) e2y - (float) e1y;

        p.rCubicTo(delta_q1x, delta_q1y, delta_q2x, delta_q2y, delta_e2x, delta_e2y);

        eta1 = eta2;
        e1x = e2x;
        e1y = e2y;
        ep1x = ep2x;
        ep1y = ep2y;
    }
}