Here you can find the source of distancePointToLine(final Point2D point, final Line2D line)
Parameter | Description |
---|---|
point | a parameter |
line | a parameter |
public static double distancePointToLine(final Point2D point, final Line2D line)
//package com.java2s; //License from project: Open Source License import java.awt.geom.Line2D; import java.awt.geom.Point2D; public class Main { /**// www .j av a2 s . c om * Given a line based on two points, and a point away from the line, find * the perpendicular distance from the point to the line. see * http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html for * explanation and defination. Source: * * @see <a href="http * ://www.java2s.com/Code/CSharp/Development-Class/DistanceFromPointToLine * .htm">DistanceFromPointToLine</a> * @param point * @param line * @return */ public static double distancePointToLine(final Point2D point, final Line2D line) { final Point2D l1 = line.getP1(); final Point2D l2 = line.getP2(); return Math .abs((l2.getX() - l1.getX()) * (l1.getY() - point.getY()) - (l1.getX() - point.getX()) * (l2.getY() - l1.getY())) / Math.sqrt(Math.pow(l2.getX() - l1.getX(), 2) + Math.pow(l2.getY() - l1.getY(), 2)); } }