get Mid Point - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

get Mid Point

Demo Code


//package com.java2s;

import java.awt.geom.Point2D;

public class Main {
    /**/*from   w  ww.  jav a2  s.  c  o  m*/
     * @return midPoint or null if any argument is invalid
     */
    public static Point2D.Double getMidPoint(Point2D ptA, Point2D ptB) {
        if (ptA != null && ptB != null) {
            return new Point2D.Double((ptA.getX() + ptB.getX()) / 2.0,
                    (ptA.getY() + ptB.getY()) / 2.0);
        }
        return null;
    }
}

Related Tutorials