本文整理汇总了Java中math.geom2d.Point2D.ccw方法的典型用法代码示例。如果您正苦于以下问题:Java Point2D.ccw方法的具体用法?Java Point2D.ccw怎么用?Java Point2D.ccw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math.geom2d.Point2D
的用法示例。
在下文中一共展示了Point2D.ccw方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intersects
import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
* Checks if two line segment intersect. Uses the Point2D.ccw() method,
* which is based on Sedgewick algorithm.
*
* @param edge1 a line segment
* @param edge2 a line segment
* @return true if the 2 line segments intersect
*/
public final static boolean intersects(LineSegment2D edge1,
LineSegment2D edge2) {
Point2D e1p1 = edge1.getFirstPoint();
Point2D e1p2 = edge1.getLastPoint();
Point2D e2p1 = edge2.getFirstPoint();
Point2D e2p2 = edge2.getLastPoint();
boolean b1 = Point2D.ccw(e1p1, e1p2, e2p1)
*Point2D.ccw(e1p1, e1p2, e2p2)<=0;
boolean b2 = Point2D.ccw(e2p1, e2p2, e1p1)
*Point2D.ccw(e2p1, e2p2, e1p2)<=0;
return b1&&b2;
}
示例2: intersects
import math.geom2d.Point2D; //导入方法依赖的package包/类
/**
* Checks if two line intersect. Uses the
* {@link math.geom2d.Point2D#ccw(Point2D, Point2D, Point2D) Point2D.ccw}
* method, which is based on Sedgewick algorithm.
*
* @param line1 a Line2D object
* @param line2 a Line2D object
* @return true if the 2 lines intersect
*/
public static boolean intersects(Line2D line1, Line2D line2) {
Point2D e1p1 = line1.getFirstPoint();
Point2D e1p2 = line1.getLastPoint();
Point2D e2p1 = line2.getFirstPoint();
Point2D e2p2 = line2.getLastPoint();
boolean b1 = Point2D.ccw(e1p1, e1p2, e2p1)
*Point2D.ccw(e1p1, e1p2, e2p2)<=0;
boolean b2 = Point2D.ccw(e2p1, e2p2, e1p1)
*Point2D.ccw(e2p1, e2p2, e1p2)<=0;
return b1&&b2;
}
示例3: convexHull
import math.geom2d.Point2D; //导入方法依赖的package包/类
public Polygon2D convexHull(Collection<? extends Point2D> points) {
int nbPoints = points.size();
//TODO: manage small values of n
// Find point with lowest y-coord
Point2D lowestPoint = null;
double lowestY = Double.MAX_VALUE;
for(Point2D point : points){
double y = point.getY();
if(y<lowestY){
lowestPoint = point;
lowestY = y;
}
}
// build the comparator, using the lowest point
Comparator<Point2D> comparator =
new CompareByPseudoAngle(lowestPoint);
// create a sorted set
ArrayList<Point2D> sorted = new ArrayList<Point2D>(nbPoints);
sorted.addAll(points);
Collections.sort(sorted, comparator);
// main loop
// i-> current vertex of point cloud
// m-> current hull vertex
int m = 2;
for(int i=3; i<nbPoints; i++){
while(Point2D.ccw(sorted.get(m), sorted.get(m-1),
sorted.get(i))>=0)
m--;
m++;
Collections.swap(sorted, m, i);
}
// Format result to return a polygon
List<Point2D> hull = sorted.subList(0, Math.min(m+1, nbPoints));
return new SimplePolygon2D(hull);
}