Search in sources :

Example 56 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class DiscretizedLocationOperator method randomizeNodes.

public void randomizeNodes() {
    List<Point2D> listLocations = new ArrayList<Point2D>();
    listLocations.addAll(allLocations);
    for (int i = 0; i < treeModel.getInternalNodeCount(); i++) {
        NodeRef node = treeModel.getInternalNode(i);
        double[] trait = treeModel.getMultivariateNodeTrait(node, traitName);
        Point2D newPt = listLocations.get(MathUtils.nextInt(listLocations.size()));
        trait[0] = newPt.getX();
        trait[1] = newPt.getY();
        recursivelySetTrait(node, trait, null);
    //            treeModel.setMultivariateTrait(node, traitName, trait);            
    }
    System.err.println("Done with randomization");
//        System.exit(-1);
}
Also used : NodeRef(dr.evolution.tree.NodeRef) Point2D(java.awt.geom.Point2D)

Example 57 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class BrownianBridge1D method divideConquerBrownianBridge.

public static int divideConquerBrownianBridge(double D, int point0, List<Point2D> points, int depth, SpaceTimeRejector1D rejector) {
    if (depth > 0) {
        Point2D p0 = points.get(point0);
        Point2D p1 = points.get(point0 + 1);
        double t0 = p0.getX();
        double y0 = p0.getY();
        double t1 = p1.getX();
        double y1 = p1.getY();
        double tm = (t1 - t0) / 2.0 + t0;
        double mean = y0 + 0.5 * (y1 - y0);
        double stdev = Math.sqrt(D * (t1 - t0) / 4.0);
        double xm = MathUtils.nextGaussian() * stdev + mean;
        if (rejector != null) {
            while (rejector.reject(tm, xm)) {
                xm = MathUtils.nextGaussian() * stdev + mean;
            }
        }
        points.add(point0 + 1, new Point2D.Double(tm, xm));
        int endPoint = divideConquerBrownianBridge(D, point0, points, depth - 1, rejector);
        return divideConquerBrownianBridge(D, endPoint, points, depth - 1, rejector);
    } else
        return point0 + 1;
}
Also used : Point2D(java.awt.geom.Point2D)

Example 58 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class AbstractPolygon2D method getCentroid.

public Point2D getCentroid() {
    //        rescaleToPositiveCoordinates();
    Point2D centroid = new Point2D.Double();
    double area = calculateArea();
    double cx = 0, cy = 0;
    double factor;
    //we can implement it like this because the polygon is closed (point2D.get(0) = point2D.get(length + 1)
    for (int i = 0; i < length; i++) {
        factor = (x[i] * y[i + 1] - x[i + 1] * y[i]);
        cx += (x[i] * x[i + 1]) * factor;
        cy += (y[i] * y[i + 1]) * factor;
    }
    double constant = 1 / (area * 6);
    cx *= constant;
    cy *= constant;
    centroid.setLocation(cx, cy);
    System.out.println("centroid = " + cx + "," + cy);
    return centroid;
}
Also used : Point2D(java.awt.geom.Point2D)

Example 59 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class CartogramMapping method map.

public Point2D map(Point2D inPt) {
    if (!boundingBox.contains(inPt))
        return null;
    if (!loaded)
        return inPt;
    final double offsetX = (inPt.getX() - boundingBox.getMinX()) / dX;
    final double offsetY = (inPt.getY() - boundingBox.getMinY()) / dY;
    final int iX = (int) offsetX;
    final int iY = (int) offsetY;
    final double rX = offsetX - iX;
    final double rY = offsetY - iY;
    assert (rX >= 0 && rY < 1.0 && rY >= 0 && rY < 1.0);
    final Point2D gridiXiY = gridPt[iX][iY];
    final Point2D gridiX1iY = gridPt[iX + 1][iY];
    final Point2D gridiXiY1 = gridPt[iX][iY + 1];
    final Point2D gridiX1iY1 = gridPt[iX + 1][iY + 1];
    final double outX = (1 - rX) * (1 - rY) * gridiXiY.getX() + rX * (1 - rY) * gridiX1iY.getX() + (1 - rX) * rY * gridiXiY1.getX() + rX * rY * gridiX1iY1.getX();
    final double outY = (1 - rX) * (1 - rY) * gridiXiY.getY() + rX * (1 - rY) * gridiX1iY.getY() + (1 - rX) * rY * gridiXiY1.getY() + rX * rY * gridiX1iY1.getY();
    return new Point2D.Double(outX, outY);
}
Also used : Point2D(java.awt.geom.Point2D)

Example 60 with Point2D

use of java.awt.geom.Point2D in project beast-mcmc by beast-dev.

the class CartogramMapping method main.

/*
     * This should replicate the behavoir of Newman's 'interp' program
     */
public static void main(String[] args) {
    int gridXSize = Integer.parseInt(args[0]);
    int gridYSize = Integer.parseInt(args[1]);
    String fileName = args[2];
    CartogramMapping mapping = new CartogramMapping(gridXSize, gridYSize, new Rectangle2D.Double(0, 0, gridXSize, gridYSize));
    try {
        mapping.readCartogramOutput(fileName);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                // end of file
                break;
            } else if (line.length() == 0) {
                break;
            } else {
                // not a blank line
                StringTokenizer st = new StringTokenizer(line);
                Point2D inPt = new Point2D.Double(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
                System.out.println(mapping.map(inPt));
            }
        }
    } catch (IOException e) {
        System.err.println(e);
        System.exit(-1);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

Point2D (java.awt.geom.Point2D)193 Color (java.awt.Color)22 Rectangle2D (java.awt.geom.Rectangle2D)20 RadialGradientPaint (java.awt.RadialGradientPaint)19 Graphics2D (java.awt.Graphics2D)18 Point (java.awt.Point)18 Paint (java.awt.Paint)17 Line2D (java.awt.geom.Line2D)12 AffineTransform (java.awt.geom.AffineTransform)11 Rectangle (java.awt.Rectangle)9 BasicStroke (java.awt.BasicStroke)8 Stroke (java.awt.Stroke)8 Ellipse2D (java.awt.geom.Ellipse2D)8 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Element (org.jdom2.Element)6 GradientPaint (java.awt.GradientPaint)5 Arc2D (java.awt.geom.Arc2D)5 GeneralPath (java.awt.geom.GeneralPath)5