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:SWTUtils.java

/**
 * Returns an SWT point with the same coordinates as the specified AWT
 * point (rounded to integer values)./*from  w  w  w .  ja  v  a2s  . co  m*/
 *
 * @param p  the AWT point (<code>null</code> not permitted).
 *
 * @return An SWT point with the same coordinates as <code>p</code>.
 *
 * @see #toAwtPoint(Point)
 */
public static Point toSwtPoint(java.awt.geom.Point2D p) {
    return new Point((int) Math.round(p.getX()), (int) Math.round(p.getY()));
}

From source file:Main.java

/**
 * Returns a point that is a google tile reference for the tile containing
 * the lat/lng and at the zoom level.//from www .j ava2  s.c  o  m
 */
public static Point toTileXY(double lat, double lng, int zoom) {
    Point2D normalised = toNormalisedPixelCoords(lat, lng);
    int scale = 1 << zoom;

    // can just truncate to integer, this looses the fractional "pixel offset"
    return new Point((int) (normalised.getX() * scale), (int) (normalised.getY() * scale));
}

From source file:com.griddynamics.jagger.diagnostics.visualization.GraphVisualizationHelper.java

private static <V, E> Layout<V, E> displacementLayout(Layout<V, E> layout, final int xOffset,
        final int yOffset) {
    return new LayoutDecorator<V, E>(layout) {
        @Override/*from ww w.  ja v  a2  s .c  o  m*/
        public Point2D transform(V v) {
            Point2D point = delegate.transform(v);
            return new Point.Double(point.getX() + xOffset, point.getY() + yOffset);
        }
    };
}

From source file:Main.java

/** Computes the intersection between two lines. The calculated point is approximate, 
 * since integers are used. If you need a more precise result, use doubles everywhere.
 * Modified from original version (by Alexander Hristov) by Eric Eaton. 
 * (c) 2007 Alexander Hristov. Use Freely (LGPL license). http://www.ahristov.com
 *
 * @param lineA the first line/*  w w  w.  ja v  a  2  s . c o  m*/
 * @param lineB the second line
 * @return point where the segments intersect, or null if they don't
 */
public static Point2D intersection(Line2D lineA, Line2D lineB) {

    Point2D lineAPt1 = lineA.getP1();
    Point2D lineAPt2 = lineA.getP2();
    Point2D lineBPt1 = lineB.getP1();
    Point2D lineBPt2 = lineB.getP2();

    double x1 = lineAPt1.getX();
    double y1 = lineAPt1.getY();
    double x2 = lineAPt2.getX();
    double y2 = lineAPt2.getY();
    double x3 = lineBPt1.getX();
    double y3 = lineBPt1.getY();
    double x4 = lineBPt2.getX();
    double y4 = lineBPt2.getY();

    double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
    if (d == 0)
        return null;

    double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
    double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;

    return new Point2D.Double(xi, yi);
}

From source file:org.jcurl.core.impl.ColliderBase.java

/**
 * Compute the inverse speed transformation to the right handed, moving
 * coordinate-system with relative speed <code>v0</code> and positive
 * y-axis pointing from <code>a</code> to <code>b</code>.
 * /*from  w  ww  .j  av a2 s  .c  om*/
 * TODO Maybe thios should operate on {@link Rock}s rather than
 * {@link Point2D}s?
 * 
 * @param v0
 * @param a
 * @param b
 * @param mat
 * @return the given matrix
 */
public static AffineTransform getInverseTrafo(final Point2D v0, final Point2D a, final Point2D b,
        final AffineTransform mat) {
    double dx = b.getX() - a.getX();
    double dy = b.getY() - a.getY();
    final double d = Math.sqrt(dx * dx + dy * dy);
    dx /= d;
    dy /= d;
    mat.setTransform(dy, -dx, dx, dy, 0, 0);
    mat.translate(-v0.getX(), -v0.getY());
    return mat;
}

From source file:org.jcurl.core.base.Collider.java

/**
 * Compute the trafo to the right handed coordinate-system with origin
 * <code>orig</code> and positive y-axis pointing from <code>a</code> to
 * <code>b</code>.//from   w  ww. j  av a 2s  . com
 * 
 * @param orig
 * @param a
 * @param b
 * @param mat
 * @return the given matrix
 */
public static AffineTransform getInverseTrafo(final Point2D orig, final Point2D a, final Point2D b,
        final AffineTransform mat) {
    double dx = b.getX() - a.getX();
    double dy = b.getY() - a.getY();
    final double d = Math.sqrt(dx * dx + dy * dy);
    dx /= d;
    dy /= d;
    mat.setTransform(dy, -dx, dx, dy, 0, 0);
    mat.translate(-orig.getX(), -orig.getY());
    return mat;
}

From source file:GraphicsUtil.java

public static void drawCentered(Graphics g, BufferedImage img, Point2D location, double newWidth,
        double newHeight, ImageObserver observer) {
    Graphics2D g2 = (Graphics2D) g;
    g2.drawImage(img, // what to draw
            (int) (location.getX() - (newWidth / 2)), // dest left
            (int) (location.getY() - (newHeight / 2)), // dest top
            (int) (location.getX() + (newWidth / 2)), // dest right
            (int) (location.getY() + (newHeight / 2)), // dest bottom
            0, // src left
            0, // src top
            img.getWidth(), // src right
            img.getHeight(), // src bottom
            observer // to notify of image updates
    );//w w  w .j  a v  a 2s.  com
}

From source file:MainWindowLogic.java

static void inputValuesIntoTableFromDataForwarder(Point2D[] pointsCollection, JTable jTabela) {
    DefaultTableModel tmp = (DefaultTableModel) jTabela.getModel();
    for (Point2D point : pointsCollection) {
        tmp.addRow(new Object[] { (tmp.getRowCount() + 1) + ".", point.getX(), point.getY(), false });
    }//from w  ww  .  j  a  v a  2s.  co  m
}

From source file:de.bund.bfr.knime.gis.GisUtils.java

public static Point2D latLonToViz(Point2D p) {
    return new Point2D.Double(new OsmMercator().lonToX(p.getY(), 0), new OsmMercator().latToY(p.getX(), 0));
}

From source file:jcurl.sim.core.SlideCurves.java

/**
 * Transform the trajectory from speed-coordinates (the y-axis points along
 * the direction of motion) to world coordinates and seed the
 * {@link Polynome}s <code>p[0]</code> and <code>p[1]</code>.
 * // www .  ja v  a2 s  .c  o m
 * @param x0
 *            initial location x(t0)
 * @param e
 *            unit vector of speed
 * @param xt
 *            trajectory x(t) in "speed-coordinates"
 * @param p
 *            array of {@link Polynome}s of which <code>p[0]</code> and
 *            <code>p[1]</code> get filled.
 */
protected static void transformRc2Wc(final Point2D x0, final Point2D e, final double[] xt, final Polynome[] p) {
    // x(t) = x0 + e * x(t)
    double[] tmp = MathVec.mult(e.getX(), xt, null);
    tmp[0] += x0.getX();
    p[0] = new Polynome(tmp);
    tmp = MathVec.mult(e.getY(), xt, null);
    tmp[0] += x0.getY();
    p[1] = new Polynome(tmp);
}