当前位置: 首页>>代码示例>>Java>>正文


Java Line2D.getX1方法代码示例

本文整理汇总了Java中java.awt.geom.Line2D.getX1方法的典型用法代码示例。如果您正苦于以下问题:Java Line2D.getX1方法的具体用法?Java Line2D.getX1怎么用?Java Line2D.getX1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.geom.Line2D的用法示例。


在下文中一共展示了Line2D.getX1方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: collides

import java.awt.geom.Line2D; //导入方法依赖的package包/类
@Override
public Point2D collides(final Line2D rayCast) {
  final Point2D rayCastSource = new Point2D.Double(rayCast.getX1(), rayCast.getY1());
  final List<Rectangle2D> collBoxes = this.getAllCollisionBoxes();
  collBoxes.sort((rect1, rect2) -> {
    final Point2D rect1Center = new Point2D.Double(rect1.getCenterX(), rect1.getCenterY());
    final Point2D rect2Center = new Point2D.Double(rect2.getCenterX(), rect2.getCenterY());
    final double dist1 = rect1Center.distance(rayCastSource);
    final double dist2 = rect2Center.distance(rayCastSource);

    if (dist1 < dist2) {
      return -1;
    }

    if (dist1 > dist2) {
      return 1;
    }

    return 0;
  });

  for (final Rectangle2D collisionBox : collBoxes) {
    if (collisionBox.intersectsLine(rayCast)) {
      double closestDist = -1;
      Point2D closestPoint = null;
      for (final Point2D intersection : GeometricUtilities.getIntersectionPoints(rayCast, collisionBox)) {
        final double dist = intersection.distance(rayCastSource);
        if (closestPoint == null || dist < closestDist) {
          closestPoint = intersection;
          closestDist = dist;
        }
      }

      return closestPoint;
    }
  }

  return null;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:40,代码来源:PhysicsEngine.java

示例5: 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

示例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(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

示例7: 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

示例8: 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

示例9: 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

示例10: 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.getX1方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。