Java Geometry Algorithm preciseFrontBumperOffset( Point2D.Double sourceLocation, Point2D.Double botLocation)

Here you can find the source of preciseFrontBumperOffset( Point2D.Double sourceLocation, Point2D.Double botLocation)

Description

precise Front Bumper Offset

License

Open Source License

Declaration

public static double preciseFrontBumperOffset(
            Point2D.Double sourceLocation, Point2D.Double botLocation) 

Method Source Code

//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;
        }
    }
}

Related

  1. plotBezier(GeneralPath path, @Nonnull Point2D p0, @Nonnull Point2D p1, @Nonnull Point2D p2, @Nonnull Point2D p3, int depth, double displacement)
  2. plus(Point point1, Point point2)
  3. polarPointAtInfinity(double angle)
  4. polarToPoint(double angle, double fx, double fy)
  5. positiveAngleBetween3Points(Point2D.Double p1, Point2D.Double p2, Point2D.Double p3)
  6. preprocess(Point2D pa, Point2D pb, Point2D pc)
  7. prodEscalar(Point2D p1, Point2D p2)
  8. project(Point2D sourceLocation, double angle, double length)
  9. project(Point2D.Double sourceLocation, double angle, double length)