Here you can find the source of preciseFrontBumperOffset( Point2D.Double sourceLocation, Point2D.Double botLocation)
public static double preciseFrontBumperOffset( Point2D.Double sourceLocation, Point2D.Double botLocation)
//package com.java2s; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Iterator; public class Main { public static double preciseFrontBumperOffset( Point2D.Double sourceLocation, Point2D.Double botLocation) { return sourceLocation.distance(botLocation) - distancePointToBot(sourceLocation, botLocation); }//from w w w . j a v a2s. c o m public static double distancePointToBot(Point2D.Double sourceLocation, Point2D.Double botLocation) { if (sourceLocation.x > botLocation.x - 18 && sourceLocation.x < botLocation.x + 18 && sourceLocation.y > botLocation.y - 18 && sourceLocation.y < botLocation.y + 18) { return 0; } else { ArrayList<Line2D.Double> botSides = new ArrayList<Line2D.Double>(); botSides.add(new Line2D.Double(botLocation.x - 18, botLocation.y - 18, botLocation.x + 18, botLocation.y - 18)); botSides.add(new Line2D.Double(botLocation.x + 18, botLocation.y - 18, botLocation.x + 18, botLocation.y + 18)); botSides.add(new Line2D.Double(botLocation.x + 18, botLocation.y + 18, botLocation.x - 18, botLocation.y + 18)); botSides.add(new Line2D.Double(botLocation.x - 18, botLocation.y + 18, botLocation.x - 18, botLocation.y - 18)); double distance = Double.POSITIVE_INFINITY; Iterator<Line2D.Double> sideIterator = botSides.iterator(); while (sideIterator.hasNext()) { distance = Math.min(distance, sideIterator.next() .ptSegDist(sourceLocation)); } return distance; } } }