Here you can find the source of distance_to_endpoint(int x1, int y1, int x2, int y2, int x, int y)
Parameter | Description |
---|---|
x1 | x coord |
y1 | y coord |
x2 | x coord |
y2 | y coord |
x | x coord of point |
y | y coord of point |
public final static float distance_to_endpoint(int x1, int y1, int x2, int y2, int x, int y)
//package com.java2s; public class Main { /**/*from w ww . j a va2s .c o m*/ * Distance to closest endpoint. * <p> * * @param x1 x coord * @param y1 y coord * @param x2 x coord * @param y2 y coord * @param x x coord of point * @param y y coord of point * @return float distance to endpoint */ public final static float distance_to_endpoint(int x1, int y1, int x2, int y2, int x, int y) { return (float) Math.min(distance(x1, y1, x, y), distance(x2, y2, x, y)); } /** * 2D distance formula. * <p> * * @param x1 x coord * @param y1 y coord * @param x2 x coord * @param y2 y coord * @return float distance */ public final static float distance(float x1, float y1, float x2, float y2) { double xdiff = x2 - x1; double ydiff = y2 - y1; return (float) Math.sqrt((xdiff * xdiff + ydiff * ydiff)); } /** * 2D distance formula. * <p> * * @param x1 x coord * @param y1 y coord * @param x2 x coord * @param y2 y coord * @return float distance */ public final static float distance(int x1, int y1, int x2, int y2) { double xdiff = x2 - x1; double ydiff = y2 - y1; return (float) Math.sqrt((xdiff * xdiff + ydiff * ydiff)); } /** * 2D distance formula. * <p> * * @param x1 x coord * @param y1 y coord * @param x2 x coord * @param y2 y coord * @return double distance */ public final static double distance(double x1, double y1, double x2, double y2) { double xdiff = x2 - x1; double ydiff = y2 - y1; return Math.sqrt((xdiff * xdiff + ydiff * ydiff)); } }