Java tutorial
//package com.java2s; /* * Copyright 2016 GcsSloop * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Last modified 2016-12-03 22:55:55 * */ import android.graphics.Point; public class Main { /** * Get the coordinates of a point on the line by cut length. * * @param A Point A * @param B Point B * @param cutLength cut length * @return the point. */ public static Point getPointByCutLength(Point A, Point B, int cutLength) { float radian = getRadian(A, B); return new Point(A.x + (int) (cutLength * Math.cos(radian)), A.y + (int) (cutLength * Math.sin(radian))); } /** * Get the radian between current line(determined by point A and B) and horizontal line. * * @param A point A * @param B point B * @return the radian */ public static float getRadian(Point A, Point B) { float lenA = B.x - A.x; float lenB = B.y - A.y; float lenC = (float) Math.sqrt(lenA * lenA + lenB * lenB); float radian = (float) Math.acos(lenA / lenC); radian = radian * (B.y < A.y ? -1 : 1); return radian; } }