本文整理汇总了Java中math.geom2d.Point2D.distance方法的典型用法代码示例。如果您正苦于以下问题:Java Point2D.distance方法的具体用法?Java Point2D.distance怎么用?Java Point2D.distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math.geom2d.Point2D
的用法示例。
在下文中一共展示了Point2D.distance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDistance
import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
* Gets the distance of the StraightObject2d to the given point. This method
* is not designed to be used directly, because AbstractLine2D is an
* abstract class, but it can be used by subclasses to help computations.
*
* @param x x-coordinate of the point
* @param y y-coordinate of the point
* @return distance between this object and the point (x,y)
*/
public double getDistance(double x, double y) {
// first project on the line
Point2D proj = getProjectedPoint(x, y);
// if the line contains the projection, returns the distance
if (contains(proj))
return proj.distance(x, y);
// otherwise, returns the distance to the closest singular point
double dist = Double.POSITIVE_INFINITY;
if(!Double.isInfinite(getT0()))
dist = getFirstPoint().getDistance(x, y);
if(!Double.isInfinite(getT1()))
dist = Math.min(dist, getLastPoint().getDistance(x, y));
return dist;
}
示例2: getDistance
import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
* Get the distance of the point (x, y) to this edge.
*/
@Override
public double getDistance(double x, double y) {
Point2D proj = super.getProjectedPoint(x, y);
if (contains(proj))
return proj.distance(x, y);
double d1 = JavaGeomMath.hypot(x0-x, y0-y);
double d2 = JavaGeomMath.hypot(x0+dx-x, y0+dy-y);
return Math.min(d1, d2);
}
示例3: getDistance
import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
* Get the distance of the point (x, y) to this edge.
*/
public double getDistance(double x, double y) {
StraightLine2D support = new StraightLine2D(p1, p2);
Point2D proj = support.getProjectedPoint(x, y);
if (contains(proj))
return proj.distance(x, y);
double d1 = JavaGeomMath.hypot(p1.getX()-x, p1.getY()-y);
double d2 = JavaGeomMath.hypot(p2.getX()-x, p2.getY()-y);
// System.out.println("dist lineObject2D : " + Math.min(d1, d2));
return Math.min(d1, d2);
}
示例4: getDistance
import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
* Returns the distance of the point (x, y) to this straight line.
*/
@Override
public double getDistance(double x, double y) {
Point2D proj = super.getProjectedPoint(x, y);
return proj.distance(x, y);
}