Find the point on the line from a given fraction from a point - Android java.lang

Android examples for java.lang:Math Geometry

Description

Find the point on the line from a given fraction from a point

Demo Code

/*******************************************************************************
 * Copyright (c) 2011 MadRobot./*  w  w w  . ja  v  a2s . c o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/
//package com.java2s;

import android.graphics.PointF;

public class Main {
    /**
     * Find the point on the line lineStart,lineEnd a given fraction from p0.
     * 
     * 
     * @param lineStart
     *            First coordinate of line [x,y].
     * @param lineEnd
     *            Second coordinate of line [x,y].
     * @param fractionFromP0
     *            Point we are looking for coordinates of
     */
    public static PointF computePointOnLine(PointF lineStart,
            PointF lineEnd, float fractionFromP0) {
        PointF point = new PointF();

        point.x = lineStart.x + fractionFromP0 * (lineEnd.x - lineStart.x);
        point.y = lineStart.y + fractionFromP0 * (lineEnd.y - lineStart.y);
        return point;
    }
}

Related Tutorials