Java Geometry Algorithm findMiddlePoint(Point2D p1, Point2D p2)

Here you can find the source of findMiddlePoint(Point2D p1, Point2D p2)

Description

Return the middle point between p1 and p2.

License

Open Source License

Parameter

Parameter Description
pointPlace a parameter
pointTransition a parameter

Return

middle point

Declaration

public static Point2D findMiddlePoint(Point2D p1, Point2D p2) 

Method Source Code

//package com.java2s;
/**//from  ww  w .j  ava2  s  . c  o  m
 * The MIT License (MIT)

 Copyright (c) 2016 Pedro Henrique Nascimento Vieira

 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 java.awt.geom.Point2D;

public class Main {
    /**
     * Return the middle point between p1 and p2.
     * @param pointPlace
     * @param pointTransition
     * @return middle point
     */
    public static Point2D findMiddlePoint(Point2D p1, Point2D p2) {
        double x = (p1.getX() + p2.getX()) / 2;

        double y = (p1.getY() + p2.getY()) / 2;

        return (new Point2D.Double(x, y));
    }

    /**
     * Return the middle point between p1 and p2.
     * @param x1
     * @param y1
     * @param x2
     * @param y2
     * @return middle point
     */
    public Point2D findMiddlePoint(double x1, double y1, double x2,
            double y2) {
        Point2D p1 = new Point2D.Double(x1, y1);
        Point2D p2 = new Point2D.Double(x2, y2);
        return (findMiddlePoint(p1, p2));
    }
}

Related

  1. findDimension(Point2D[] pts)
  2. findDistancedPoint(double t, Point2D sp, Point2D c1, Point2D c2, Point2D ep)
  3. findIntersect(Point2D p1, Point2D p2, Point2D p3, Point2D p4)
  4. findIntersection(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3, Point2D.Double p4)
  5. findLineSegmentIntersection(Line2D one, Line2D two, Point2D intersection)
  6. fitCircle(final Point2D P1, final Point2D P2, final Point2D P3)
  7. forceMouseMove(Point pos)
  8. generateLine(Point2D.Double point, double length, double angle)
  9. generateLookAtTag(ArrayList geoCoords, ArrayList modsAM)