Example usage for java.awt.geom Point2D getX

List of usage examples for java.awt.geom Point2D getX

Introduction

In this page you can find the example usage for java.awt.geom Point2D getX.

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:Main.java

private static double extractAngle(AffineTransform at) {
    Point2D p0 = new Point();
    Point2D p1 = new Point(1, 0);
    Point2D pp0 = at.transform(p0, null);
    Point2D pp1 = at.transform(p1, null);
    double dx = pp1.getX() - pp0.getX();
    double dy = pp1.getY() - pp0.getY();
    double angle = Math.atan2(dy, dx);
    return angle;
}

From source file:Main.java

/** Does linear interpolation at x of the line from pt1 to pt2.
 * @param pt1 one endpoint of the line./*from   w w  w  . j av  a 2s  .  c  o m*/
 * @param pt2 another endpoint of the line.
 * @param x the x-coordinate of the interpolated point.
 * @return the desired interpolated point.
 */
public static Point2D interpolate(Point2D pt1, Point2D pt2, double x) {
    double slope = (pt2.getY() - pt1.getY()) / (pt2.getX() - pt1.getX());
    double y = pt1.getY() + (x - pt1.getX()) * slope;
    return new Point2D.Double(x, y);
}

From source file:Main.java

/** Interpolates the given x onto the line of points.
 * @param points//  w  ww .ja v  a2s. c o m
 * @param x
 * @return x interpolated onto the line defined by the points
 */
public static Point2D interpolate(Point2D[] points, double x) {
    // determine the two point boundaries for the line segment
    for (int i = 0; i < points.length - 1; i++) {
        Point2D pt1 = points[i];
        Point2D pt2 = points[i + 1];
        if (x == pt1.getX())
            return new Point2D.Double(pt1.getX(), pt1.getY());
        else if (x < pt2.getX())
            return interpolate(pt1, pt2, x);
    }

    // if we reach here, then x >= the last point
    Point2D pt1 = points[points.length - 2];
    Point2D pt2 = points[points.length - 1];
    if (x == pt2.getX())
        return new Point2D.Double(pt2.getX(), pt2.getY());
    else
        return interpolate(pt1, pt2, x);
}

From source file:FindHullWindowLogic.java

static private boolean areTheSamePoints(Point2D p1, Point2D p2) {
    if (p1.getX() == p2.getX() && p1.getY() == p2.getY())
        return true;
    else// w ww  .j  av a 2s  . c  om
        return false;
}

From source file:GeometryUtilities.java

public static boolean isBetween(Point2D a, Point2D b, Point2D c) {
    double u = c.getX() - a.getX();
    double v = c.getY() - a.getY();
    double tx = (b.getX() - a.getX()) / u;
    double ty = (b.getY() - a.getY()) / v;

    return (tx > 0 && tx < 1) || (ty > 0 && ty < 1);
}

From source file:MonteCarloWindowLogic.java

static private void convertArrayListToXYSeries(XYSeries seriesDestination, ArrayList<Point2D> arrListFrom) {
    for (Point2D onePoint : arrListFrom) {
        seriesDestination.add(onePoint.getX(), onePoint.getY());
    }//  ww w  . j a v  a2 s  .  c  om
}

From source file:Utils.java

public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius) {

    if (sides < 3) {
        return new Ellipse2D.Float(0, 0, 10, 10);
    }//from w w w .  j a v a  2s  .  c  o m

    AffineTransform trans = new AffineTransform();
    Polygon poly = new Polygon();
    for (int i = 0; i < sides; i++) {
        trans.rotate(Math.PI * 2 / (float) sides / 2);
        Point2D out = trans.transform(new Point2D.Float(0, outsideRadius), null);
        poly.addPoint((int) out.getX(), (int) out.getY());
        trans.rotate(Math.PI * 2 / (float) sides / 2);
        if (insideRadius > 0) {
            Point2D in = trans.transform(new Point2D.Float(0, insideRadius), null);
            poly.addPoint((int) in.getX(), (int) in.getY());
        }
    }

    return poly;
}

From source file:org.jcurl.mr.exp.gui.MouseSketchPanel.java

private static void circle(Graphics g, Point2D c, int r) {
    final int x = (int) c.getX();
    final int y = (int) c.getY();
    final int d = 2 * r;
    g.drawArc(x - r, y - r, d, d, 0, 360);
}

From source file:GraphicsUtil.java

public static void drawString(Graphics g, String text, RectangularShape bounds, Align align, double angle) {
    Graphics2D g2 = (Graphics2D) g;
    Font font = g2.getFont();/*from   w  ww.j  a  v  a  2  s .c o m*/
    if (angle != 0)
        g2.setFont(font.deriveFont(AffineTransform.getRotateInstance(Math.toRadians(angle))));

    Rectangle2D sSize = g2.getFontMetrics().getStringBounds(text, g2);
    Point2D pos = getPoint(bounds, align);
    double x = pos.getX();
    double y = pos.getY() + sSize.getHeight();

    switch (align) {
    case North:
    case South:
    case Center:
        x -= (sSize.getWidth() / 2);
        break;
    case NorthEast:
    case East:
    case SouthEast:
        x -= (sSize.getWidth());
        break;
    case SouthWest:
    case West:
    case NorthWest:
        break;
    }

    g2.drawString(text, (float) x, (float) y);
    g2.setFont(font);
}

From source file:FindHullWindowLogic.java

static private void addPointsToSeries(XYSeries seriesDestination) {
    for (Point2D onePoint : importedPointsFromPointsReader) {
        seriesDestination.add(onePoint.getX(), onePoint.getY());
    }/* w w w .j  a v  a  2s .co m*/
}