當前位置: 首頁>>代碼示例>>Java>>正文


Java Line2D.getX2方法代碼示例

本文整理匯總了Java中java.awt.geom.Line2D.getX2方法的典型用法代碼示例。如果您正苦於以下問題:Java Line2D.getX2方法的具體用法?Java Line2D.getX2怎麽用?Java Line2D.getX2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.geom.Line2D的用法示例。


在下文中一共展示了Line2D.getX2方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPerpendicularIntersection

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
 * Gets the perpendicular intersection.
 *
 * @param point
 *          the point
 * @param line
 *          the line
 * @return the perpendicular intersection
 */
public static Point2D getPerpendicularIntersection(final Point2D point, final Line2D line) {
  final double x1 = line.getX1();
  final double y1 = line.getY1();
  final double x2 = line.getX2();
  final double y2 = line.getY2();

  final double x3 = point.getX();
  final double y3 = point.getY();

  final double k = ((y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1)) / (Math.pow(y2 - y1, 2) + Math.pow(x2 - x1, 2));
  final double x4 = x3 - k * (y2 - y1);
  final double y4 = y3 + k * (x2 - x1);

  return new Point2D.Double(x4, y4);
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:25,代碼來源:GeometricUtilities.java

示例2: isParallel

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
 * 
 * @param line1
 * @param line2
 * @return
 */
public static boolean isParallel(Line2D line1, Line2D line2) {
    float x1 = (float) line1.getX1();
    float y1 = (float) line1.getY1();
    float x2 = (float) line1.getX2();
    float y2 = (float) line1.getY2();
    float dx = x2 - x1;
    float dy = y1 - y2;
    float d = (float) Math.sqrt((double) (dx * dx + dy * dy));

    float slope1 = Math.abs(dx / d);


    x1 = (float) line2.getX1();
    y1 = (float) line2.getY1();
    x2 = (float) line2.getX2();
    y2 = (float) line2.getY2();
    dx = x2 - x1;
    dy = y1 - y2;
    d = (float) Math.sqrt((double) (dx * dx + dy * dy));

    float slope2 = Math.abs(dx / d);

    return (slope1 == slope2);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:GeometryUtils.java

示例3: extendLine

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
 * Creates a new line by extending an existing line.
 * 
 * @param line  the line (<code>null</code> not permitted).
 * @param startPercent  the amount to extend the line at the start point 
 *                      end.
 * @param endPercent  the amount to extend the line at the end point end.
 * 
 * @return A new line.
 */
private Line2D extendLine(Line2D line, double startPercent, 
                          double endPercent) {
    if (line == null) {
        throw new IllegalArgumentException("Null 'line' argument.");
    }
    double x1 = line.getX1();
    double x2 = line.getX2();
    double deltaX = x2 - x1;
    double y1 = line.getY1();
    double y2 = line.getY2();
    double deltaY = y2 - y1;
    x1 = x1 - (startPercent * deltaX);
    y1 = y1 - (startPercent * deltaY);
    x2 = x2 + (endPercent * deltaX);
    y2 = y2 + (endPercent * deltaY);
    return new Line2D.Double(x1, y1, x2, y2);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:28,代碼來源:RingPlot.java

示例4: getIntersectionPoint

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
 * Gets the intersection point.
 *
 * @param lineA
 *          the line a
 * @param lineB
 *          the line b
 * @return the intersection point
 */
public static Point2D getIntersectionPoint(final Line2D lineA, final Line2D lineB) {

  final double x1 = lineA.getX1();
  final double y1 = lineA.getY1();
  final double x2 = lineA.getX2();
  final double y2 = lineA.getY2();

  final double x3 = lineB.getX1();
  final double y3 = lineB.getY1();
  final double x4 = lineB.getX2();
  final double y4 = lineB.getY2();

  Point2D p = null;

  final double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  if (d != 0) {
    final double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
    final double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;

    if (xi >= Math.min(lineA.getX1(), lineA.getX2()) && xi <= Math.max(lineA.getX1(), lineA.getX2()) && yi >= Math.min(lineA.getY1(), lineA.getY2()) && yi <= Math.max(lineA.getY1(), lineA.getY2())) {
      p = new Point2D.Double(xi, yi);
    }
  }

  return p;
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:36,代碼來源:GeometricUtilities.java

示例5: convertBoundsAndSetDropLine

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/** Converts line's bounds by the bounds of the root pane. Drop glass pane
 * is over this root pane. After covert a given line is set to drop glass pane.
 * @param line line for show in drop glass pane */
private void convertBoundsAndSetDropLine(final Line2D line) {
    int x1 = (int) line.getX1();
    int x2 = (int) line.getX2();
    int y1 = (int) line.getY1();
    int y2 = (int) line.getY2();
    Point p1 = SwingUtilities.convertPoint(tree, x1, y1, tree.getRootPane());
    Point p2 = SwingUtilities.convertPoint(tree, x2, y2, tree.getRootPane());
    line.setLine(p1, p2);
    if( null != dropPane )
        dropPane.setDropLine(line);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:TreeViewDropSupport.java

示例6: convertBoundsAndSetDropLine

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/** Converts line's bounds by the bounds of the root pane. Drop glass pane
 * is over this root pane. After covert a given line is set to drop glass pane.
 * @param line line for show in drop glass pane */
private void convertBoundsAndSetDropLine(final Line2D line) {
    int x1 = (int) line.getX1();
    int x2 = (int) line.getX2();
    int y1 = (int) line.getY1();
    int y2 = (int) line.getY2();
    Point p1 = SwingUtilities.convertPoint(table, x1, y1, table.getRootPane());
    Point p2 = SwingUtilities.convertPoint(table, x2, y2, table.getRootPane());
    line.setLine(p1, p2);
    dropPane.setDropLine(line);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:OutlineViewDropSupport.java

示例7: 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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:54,代碼來源:GeometryUtils.java

示例8: isBelow

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
 * Determines if the given point is below the given line. If the line is perfectly vertical, below is defined as
 * being to the right of.
 *
 * @param line The line
 * @param p The point to compare
 * @return True if the point is below the line.
 */
public static boolean isBelow(Line2D line, Point p) {
    return (line.getX2() - line.getX1()) * (p.y - line.getY1()) - (line.getY2() - line.getY1()) * (p.x - line.getX1()) > 0;
}
 
開發者ID:defano,項目名稱:jmonet,代碼行數:12,代碼來源:Geometry.java

示例9: isAbove

import java.awt.geom.Line2D; //導入方法依賴的package包/類
/**
 * Determines if the given point is above the given line. If the line is perfectly vertical, above is defined as
 * being to the left of.
 *
 * @param line The line
 * @param p The point to compare
 * @return True if the point is above the line.
 */
public static boolean isAbove(Line2D line, Point p) {
    return (line.getX2() - line.getX1()) * (p.y - line.getY1()) - (line.getY2() - line.getY1()) * (p.x - line.getX1()) < 0;
}
 
開發者ID:defano,項目名稱:jmonet,代碼行數:12,代碼來源:Geometry.java


注:本文中的java.awt.geom.Line2D.getX2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。