Here you can find the source of getDistanceToCenter(Point2D p, Line2D line)
public static double getDistanceToCenter(Point2D p, Line2D line)
//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()); } }