Java tutorial
//package com.java2s; /** * ArcUtils.java * * Copyright (c) 2014 BioWink GmbH. * * 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 android.graphics.Path; import android.graphics.PointF; import android.support.annotation.NonNull; import static java.lang.Math.sqrt; public class Main { public static void addBezierArcToPath(@NonNull Path path, @NonNull PointF center, @NonNull PointF start, @NonNull PointF end, boolean moveToStart) { if (moveToStart) { path.moveTo(start.x, start.y); } if (start.equals(end)) { return; } final double ax = start.x - center.x; final double ay = start.y - center.y; final double bx = end.x - center.x; final double by = end.y - center.y; final double q1 = ax * ax + ay * ay; final double q2 = q1 + ax * bx + ay * by; final double k2 = 4d / 3d * (sqrt(2d * q1 * q2) - q2) / (ax * by - ay * bx); final float x2 = (float) (center.x + ax - k2 * ay); final float y2 = (float) (center.y + ay + k2 * ax); final float x3 = (float) (center.x + bx + k2 * by); final float y3 = (float) (center.y + by - k2 * bx); path.cubicTo(x2, y2, x3, y3, end.x, end.y); } }