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:controller.VisLP.java

/**
 * Draw the linear constraints of an {@code LP} and color
 * it's feasible region in a given {@code CCSystem}.
 * /*from   w  w  w  .  j  a v a2s  .  c  om*/
 * @param cs
 *        a {@code CCSystem}.
 * @param lp
 *        a {@code LP}.
 */
static void drawLP(CCSystem cs, LP lp) {
    cs.clear();

    /* Don't draw the LP if it is not in two variables */
    if (lp == null || lp.getNoBasic() != 2) {
        cs.setVisibleAxes(false);
        return;
    }
    cs.setVisibleAxes(true);

    CCSLine line;
    FieldMatrix<BigFraction> cons = lp.getConstraints();
    cons = checkForBounds(cons);

    /* Draw all constraints as lines, except hidden bounded constraint */
    for (int i = 0; i < cons.getRowDimension() - 1; i++) {
        line = new CCSLine(cons.getEntry(i, 0).doubleValue(), cons.getEntry(i, 1).doubleValue(),
                cons.getEntry(i, 2).doubleValue(), Color.gray);
        cs.addLine(line);
    }

    Point2D[] fpoints = getFeasibleIntersections(cons);

    /* 
     * Move the center of the coordinate system
     * to the center of the feasible region.
     */
    if (readScope) {
        scopeArea(cs, fpoints, true);
        readScope = false;
    }
    if (feasScope && lp.feasible(false)) {
        scopeArea(cs, fpoints, false);
        feasScope = false;
    }

    /* If there is no feasible region there is no need to try to color it */
    if (fpoints.length == 0)
        return;

    /* Draw all feasible solutions as points */
    Point2D[] pconv = convex(fpoints);
    for (Point2D p2d : pconv) {
        CCSPoint ccsp = new CCSPoint(p2d.getX(), p2d.getY());
        if (!unb.contains(p2d))
            cs.addPoint(ccsp);
    }

    /* Color the region depending on whether it is unbounded or not. */
    if (unb.size() == 0) {
        cs.addPolygon(new CCSPolygon(pconv, Color.pink, true));
    } else if (unb.size() == 1) {
        GradientPaint gp = new GradientPaint(pconv[0], Color.pink, unb.get(0), cs.getBackground());
        cs.addPolygon(new CCSPolygon(pconv, gp, true));
    } else {
        Point2D p1 = unb.get(0);
        Point2D p2 = unb.get(1);
        double xavg = (p1.getX() + p2.getX()) / 2.0;
        double yavg = (p1.getY() + p2.getY()) / 2.0;
        /* 
         * Move the end point of the gradient further away from the
         * polygon edge to make the end of the gradient look less sudden.
         */
        xavg *= 0.9;
        yavg *= 0.9;

        Point2D pavg = new Point2D.Double(xavg, yavg);

        /* Fade into the background color */
        GradientPaint gp = new GradientPaint(pconv[0], Color.pink, pavg, cs.getBackground());

        cs.addPolygon(new CCSPolygon(pconv, gp, true));
    }

    /* Draw the current objective function */
    FieldVector<BigFraction> obj = lp.getObjFunction();
    line = new CCSLine(obj.getEntry(0).doubleValue(), obj.getEntry(1).doubleValue(), lp.objVal().doubleValue(),
            Color.red);
    cs.addLine(line);

    /* Draw the current basic solution as a point. */
    BigFraction[] point = lp.point();
    cs.addPoint(new CCSPoint(point[0].doubleValue(), point[1].doubleValue(), Color.red, true));
}

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param entity/*ww  w.j av  a 2s  .  co m*/
 * @param chartPanel
 * @param center
 * @return
 */
public static Shape toViewXY(Shape entity, ChartPanel chartPanel, Point2D center) {
    AffineTransform toPosition = getModelToViewTransformXY(chartPanel, center.getX(), center.getY());
    toPosition.concatenate(getTranslateInstance(-center.getX(), -center.getY()));
    return toPosition.createTransformedShape(entity);
}

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param entity/*from w ww .j a  v a2 s.com*/
 * @param chartPanel
 * @return
 */
public static Point2D toViewXY(Point2D entity, ChartPanel chartPanel) {
    AffineTransform toPosition = getModelToViewTransformXY(chartPanel, entity.getX(), entity.getY());
    toPosition.concatenate(getTranslateInstance(-entity.getX(), -entity.getY()));
    return toPosition.transform(entity, null);
}

From source file:smanilov.mandelbrot.compute.Computer.java

/**
 * Converts a pixel coordinate into a complex number.
 * @param pixelCenter The center of the pixel coordinate system.
 * @param scale log2(pixels) per unit in the complex plane. 
 * @param center The center of the view on the complex plane.
 *//*from  www.  ja v  a2 s  .  c o m*/
private static Complex toComplex(double x, double y, Point pixelCenter, int scale, Point2D center) {
    double dx = (double) (x - pixelCenter.getX());
    double dy = (double) (-y + pixelCenter.getY());
    double real = (double) dx / (1 << scale) + center.getX();
    double imaginary = (double) dy / (1 << scale) + center.getY();
    return new Complex(real, imaginary);
}

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param s//from   ww  w.j a  va  2s  .  c  o  m
 * @param baseX
 * @param baseY
 * @param scalex
 * @param scaley
 * @return
 */
public static AffineTransform scaleAtOrigin(Shape s, double baseX, double baseY, float scalex, float scaley) {
    Point2D center = new Point2D.Double(baseX, baseY);
    //Affine transforms are applied from right to left
    AffineTransform at = getTranslateInstance(center.getX(), center.getY());
    at.concatenate(getScaleInstance(scalex, scaley));
    return at;
}

From source file:net.sqs2.omr.session.logic.PageImageRenderer.java

private static void drawFormAreas(int pageIndex, float densityThreshold, FormMaster master,
        PageTaskResult pageTaskResult, Graphics2D g, MarkRecognitionConfig markRecognizationConfig,
        DeskewedImageSource pageSource, int focusedColumnIndex, Rectangle scope) {
    int formAreaIndexInPage = 0;

    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxY = Integer.MIN_VALUE;

    for (FormArea formArea : master.getFormAreaListByPageIndex(pageIndex)) {
        FormAreaResult result = (FormAreaResult) pageTaskResult.getPageAreaResultList()
                .get(formAreaIndexInPage);
        if (formArea.isMarkArea()) {
            if (focusedColumnIndex == formArea.getQuestionIndex()) {

                Rectangle rect = formArea.getRect();

                Point2D p1 = pageSource.getPoint((int) rect.getX(), (int) rect.getY());
                Point2D p2 = pageSource.getPoint((int) (rect.getX() + rect.getWidth()),
                        (int) (rect.getY() + rect.getHeight()));

                minX = Math.min(minX, (int) p1.getX());
                minY = Math.min(minY, (int) p1.getY());
                maxX = Math.max(maxX, (int) p2.getX());
                maxY = Math.max(maxY, (int) p2.getY());

                if (result.getDensity() < densityThreshold) {
                    g.setColor(FOCUSED_MARKED_COLOR);
                } else {
                    g.setColor(FOCUSED_NO_MARKED_COLOR);
                }/*from   w  w  w  .  j  a v  a  2 s .  c  om*/

            } else {
                if (result.getDensity() < densityThreshold) {
                    g.setColor(MARKED_COLOR);
                } else {
                    g.setColor(NO_MARKED_COLOR);
                }
            }

            g.fillPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin(),
                            markRecognizationConfig.getVerticalMargin())));
            g.drawPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin() + 3,
                            markRecognizationConfig.getVerticalMargin() + 3)));

        } else {
            g.setColor(TEXTAREA_COLOR);
            g.fillPolygon(pageSource.createRectPolygon(formArea.getRect()));
        }
        formAreaIndexInPage++;
    }

    if (scope != null) {
        int borderMarginX = 20;
        int borderMarginY = 3;
        int margin = 40;

        int x = minX - borderMarginX;
        int y = minY - borderMarginY;
        int width = maxX - minX + borderMarginX * 2;
        int height = maxY - minY + borderMarginY * 2;

        scope.x = minX - margin;
        scope.y = minY - margin;
        scope.width = maxX - minX + margin * 2;
        scope.height = maxY - minY + margin * 2;

        Stroke stroke = new BasicStroke(4.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 2.0f,
                new float[] { 4.0f, 8.0f }, 0.0f);
        g.setStroke(stroke);
        g.setColor(FOCUSED_SCOPE_COLOR);
        g.drawRoundRect(x, y, width, height, 20, 20);
    }

}

From source file:controller.VisLP.java

/**
 * @param  points//from w  ww  . j  a  va 2 s.co  m
 *         Unordered list of points that can form a
 *         convex polygon, but in the given order
 *         does not necessarily form a convex
 *         polygon if edges are drawn between the
 *         points in the given order.
 * @return 
 *         An ordered list of points that when edges
 *         are drawn in this order is guaranteed to
 *         form a convex polygon.
 */
static Point2D[] convex(Point2D[] points) {
    /* 
     * Sort the points first on x-value then
     * on y-value, both in ascending order.
     */
    Arrays.sort(points, new Comparator<Point2D>() {
        @Override
        public int compare(Point2D o1, Point2D o2) {
            double s = o1.getX() - o2.getX();
            if (s > 0)
                return 1;
            if (s < 0)
                return -1;

            s = o1.getY() - o2.getY();
            if (s > 0)
                return 1;
            if (s < 0)
                return -1;

            return 0;
        }
    });

    Point2D x_min = points[0];
    Point2D x_max = points[points.length - 1];

    ArrayList<Point2D> upper = new ArrayList<Point2D>();
    ArrayList<Point2D> lower = new ArrayList<Point2D>();

    upper.add(x_min);

    /* Find the slope of the line L connecting x_min and x_max */
    double mx = x_max.getX() - x_min.getX();
    double my = x_max.getY() - x_min.getY();
    double m = my / mx;

    /* Intersection of y-axis */
    double b = x_max.getY() - (m * x_max.getX());

    /* Add points above/below L to upper/lower, respectively */
    for (int i = 1; i < points.length - 1; i++) {
        Point2D p2d = points[i];
        double y = p2d.getX() * m + b;

        if (p2d.getY() >= y)
            upper.add(p2d);
        else
            lower.add(p2d);
    }

    /* Sort the lower list in descending order */
    lower.add(x_max);
    Collections.reverse(lower);

    upper.addAll(lower);
    return upper.toArray(new Point2D[0]);
}

From source file:com.t_oster.visicut.misc.Helper.java

public static Point toPoint(Point2D p) {
    return new Point((int) p.getX(), (int) p.getY());
}

From source file:com.t_oster.visicut.misc.Helper.java

/**
* Compute the rotation angle of an affine transformation.
* Counter-clockwise rotation is considered positive.
*
* method taken from http://javagraphics.blogspot.com/
*
* @return rotation angle in radians (beween -pi and pi),
*  or NaN if the transformation is bogus.
*//*from  ww  w . j  av  a2s  . c  o m*/
public static double getRotationAngle(AffineTransform transform) {
    transform = (AffineTransform) transform.clone();
    // Eliminate any post-translation
    transform.preConcatenate(
            AffineTransform.getTranslateInstance(-transform.getTranslateX(), -transform.getTranslateY()));
    Point2D p1 = new Point2D.Double(1, 0);
    p1 = transform.transform(p1, p1);
    return Math.atan2(p1.getY(), p1.getX());
}

From source file:ShapeTransform.java

/**
 * Resizes a line. Instead of creating a GeneralPath (as AffineTransform's
 * scale would do) we modify the line itself.
 * //  w  w  w  .  j a va  2s .  c o m
 * @param line
 *          the line that should be scaled
 * @param width
 *          the new width of the line bounds
 * @param height
 *          the new height of the line bounds
 * @return the scale Line2D object.
 */
private static Line2D resizeLine(final Line2D line, final double width, final double height) {
    final Line2D newLine = getNormalizedLine(line);
    final Point2D p1 = newLine.getP1();
    final Point2D p2 = newLine.getP2();
    final double normPointX = (p1.getX() - p2.getX());
    final double normPointY = (p1.getY() - p2.getY());
    final double scaleX = (normPointX == 0) ? 1 : width / Math.abs(normPointX);
    final double scaleY = (normPointY == 0) ? 1 : height / Math.abs(normPointY);
    p2.setLocation((p2.getX() - p1.getX()) * scaleX + p1.getX(), (p2.getY() - p1.getY()) * scaleY + p1.getY());
    newLine.setLine(p1, p2);
    return newLine;
}