Java Distance between Point and Line getDistanceToCenter(Point2D p, Line2D line)

Here you can find the source of getDistanceToCenter(Point2D p, Line2D line)

Description

get Distance To Center

License

Open Source License

Declaration

public static double getDistanceToCenter(Point2D p, Line2D line) 

Method Source Code

//package com.java2s;
/*// ww w. j a va 2 s .co  m
 * Copyright (c) 2014 tabletoptool.com team.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     rptools.com team - initial implementation
 *     tabletoptool.com team - further development
 */

import java.awt.geom.Line2D;

import java.awt.geom.Point2D;

public class Main {
    public static double getDistanceToCenter(Point2D p, Line2D line) {

        Point2D midPoint = new Point2D.Double((line.getP1().getX() + line.getP2().getX()) / 2,
                (line.getP1().getY() + line.getP2().getY()) / 2);

        return Math.hypot(midPoint.getX() - p.getX(), midPoint.getY() - p.getY());
    }
}

Related

  1. distanceToLine(Point2D p, Point2D endA, Point2D endZ)
  2. distanceToLine2(Line2D l, Point2D p)
  3. distanceToLine3(Line2D l, Point2D p)
  4. getDistance(double aX, double aY, double bX, double bY)
  5. getDistance(Line2D aSegment, Point aPoint)