get Collinear Point With Ratio - Java java.lang

Java examples for java.lang:Math Geometry Line

Description

get Collinear Point With Ratio

Demo Code


//package com.java2s;

import java.awt.geom.Point2D;

public class Main {
    /**//from   w ww .j ava2 s.  c  o  m
     * @param ptA
     *            first point of line segment
     * @param ptB
     *            last point of line segment
     * @param k
     *            represents ratio between AB and AC, ptC being the returned point along AB line segment.<br>
     *            If >1 , ptC point will be located on extension of AB<br>
     *            If <0 , ptC point will be located on extension of BA <br>
     *            If >0 && <AB , ptC point will be interior of AB<br>
     * @return New point ptC coordinates or null if any argument is invalid
     */
    public static Point2D.Double getCollinearPointWithRatio(Point2D ptA,
            Point2D ptB, double k) {
        if (ptA != null && ptB != null) {
            return new Point2D.Double(
                    ptB.getX() * k + ptA.getX() * (1 - k), ptB.getY() * k
                            + ptA.getY() * (1 - k));
        }
        return null;
    }
}

Related Tutorials