本文整理匯總了Java中java.awt.geom.Line2D.intersectsLine方法的典型用法代碼示例。如果您正苦於以下問題:Java Line2D.intersectsLine方法的具體用法?Java Line2D.intersectsLine怎麽用?Java Line2D.intersectsLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.geom.Line2D
的用法示例。
在下文中一共展示了Line2D.intersectsLine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getIntersectionPoint
import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
*
* @param line1
* @param line2
* @param extrapolate
* @return
*/
public static Point2D getIntersectionPoint(Line2D line1, Line2D line2,
boolean extrapolate) {
if (extrapolate || line1.intersectsLine(line2)) {
float x1 = (float) line2.getX1();
float y1 = (float) line2.getY1();
float x2 = (float) line2.getX2();
float y2 = (float) line2.getY2();
float xp1 = (float) line1.getX1();
float yp1 = (float) line1.getY1();
float xp2 = (float) line1.getX2();
float yp2 = (float) line1.getY2();
float y = 0;
float x = 0;
float dy = y2 - y1;
float s = (x2 - x1) / dy;
float dpy = yp2 - yp1;
float sp = (xp2 - xp1) / dpy;
if (y1 == y2) {
if (dpy == 0) {
return null;
}
y = y1;
x = xp1 + sp * (y - yp1);
} else if (yp1 == yp2) {
if (dy == 0) {
return null;
}
y = yp1;
x = x1 + s * (y - y1);
} else {
if (dy == 0 || dpy == 0 || (s - sp) == 0) {
return null;
}
y = (xp1 - x1 + s * y1 - sp * yp1) / (s - sp);
x = x1 + s * (y - y1);
}
return new Point2D.Float(x, y);
}
return null;
}