Example usage for java.awt.geom Point2D getY

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

Introduction

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

Prototype

public abstract double getY();

Source Link

Document

Returns the Y coordinate of this Point2D in double precision.

Usage

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.CustomLegendGraphic.java

private static LinearGradientPaint getTranslatedLinearGradientPaint(LinearGradientPaint gradient,
        Point2D startPoint, Point2D endPoint, boolean vertical) {
    if (vertical) {
        return new LinearGradientPaint(0f, (float) startPoint.getY(), 0f, (float) endPoint.getY(),
                gradient.getFractions(), gradient.getColors());
    } else {//from   w w w  .  j a va 2s .c o  m
        return new LinearGradientPaint((float) startPoint.getX(), 0f, (float) endPoint.getX(), 0f,
                gradient.getFractions(), gradient.getColors());
    }
}

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 w w .  ja  va  2s.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: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:SWTUtils.java

/**
 * Returns an SWT point with the same coordinates as the specified AWT
 * point (rounded to integer values)./*  w w w. j  a  v  a  2  s  .  c  o 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: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   www  .  ja v  a  2s .  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

/**
 * Returns a point that is a google tile reference for the tile containing
 * the lat/lng and at the zoom level./*from  w  ww.  j a v  a  2  s  . c om*/
 */
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: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 va2s  .co  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: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 });
    }/* ww w  .j a va 2  s.c  om*/
}

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 w w  . java  2 s. c  o m
 * 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>./*  ww  w . j a va 2  s . c  o  m*/
 * 
 * @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;
}