Search in sources :

Example 61 with Point2D

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

the class NumericalSpaceTimeProbs2D method main.

public static void main(String[] args) throws FileNotFoundException {
    Rectangle2D bounds = new Rectangle2D.Double(0, 0, 1, 1);
    MultivariateNormalDistribution D = new MultivariateNormalDistribution(new double[] { 0.0 }, new double[][] { { 1, 0 }, { 0, 1 } });
    NumericalSpaceTimeProbs2D nstp2D = new NumericalSpaceTimeProbs2D(50, 50, 50, 1, 0.02, bounds, D, SpaceTimeRejector.Utils.createSimpleBounds2D(bounds));
    long startTime = System.currentTimeMillis();
    nstp2D.populate(0, 0, 1000, true);
    long stopTime = System.currentTimeMillis();
    System.out.println("Time taken = " + (stopTime - startTime) / 1000 + " seconds");
    for (int i = 0; i < 10; i++) {
        Point2D start = new Point2D.Double(Math.random(), Math.random());
        Point2D end = new Point2D.Double(Math.random(), Math.random());
        double time = Math.random();
        double p = nstp2D.getProb(start, end, time);
        System.out.println("Pr(" + end.getX() + ", " + end.getY() + " | " + start.getX() + ", " + start.getY() + ", t=" + time + ") = " + p);
    }
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) MultivariateNormalDistribution(dr.math.distributions.MultivariateNormalDistribution)

Example 62 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class LayoutSlip method getBounds.

/**
     * @return the bounds of this slip
     */
public Rectangle2D getBounds() {
    Rectangle2D result;
    Point2D pointA = getCoordsA();
    result = new Rectangle2D.Double(pointA.getX(), pointA.getY(), 0, 0);
    result.add(getCoordsB());
    result.add(getCoordsC());
    result.add(getCoordsD());
    return result;
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 63 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class LayoutSlip method drawSlipState.

private void drawSlipState(Graphics2D g2, int state) {
    int ctrX = 20;
    int ctrY = 20;
    Point2D ldispA = new Point2D.Double(-20.0, 0.0);
    Point2D ldispB = new Point2D.Double(-14.0, 14.0);
    g2.setColor(Color.black);
    Point2D A = new Point2D.Double(ctrX + ldispA.getX(), ctrY + ldispA.getY());
    Point2D B = new Point2D.Double(ctrX + ldispB.getX(), ctrY + ldispB.getY());
    Point2D C = new Point2D.Double(ctrX - ldispA.getX(), ctrY - ldispA.getY());
    Point2D D = new Point2D.Double(ctrX - ldispB.getX(), ctrY - ldispB.getY());
    g2.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, C)));
    g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, A)));
    if (state == STATE_AC || state == STATE_BD || state == UNKNOWN) {
        g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
        g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
        if (getSlipType() == DOUBLE_SLIP) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, C)));
            g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, B)));
        }
    } else {
        g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
        g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
    }
    if (getSlipType() == DOUBLE_SLIP) {
        if (state == STATE_AC) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, C));
        } else if (state == STATE_BD) {
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(B, D));
        } else if (state == STATE_AD) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, C)));
            g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, B)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, D));
        } else if (state == STATE_BC) {
            g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(B, C));
        } else {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
        }
    } else {
        g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
        g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
        if (state == STATE_AD) {
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, D));
        } else if (state == STATE_AC) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, C));
        } else if (state == STATE_BD) {
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(B, D));
        } else {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) Line2D(java.awt.geom.Line2D)

Example 64 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class LayoutTurnout method scaleCoords.

public void scaleCoords(float xFactor, float yFactor) {
    Point2D pt = new Point2D.Double(Math.round(center.getX() * xFactor), Math.round(center.getY() * yFactor));
    center = pt;
    if (version == 2) {
        pointA = new Point2D.Double(Math.round(pointA.getX() * xFactor), Math.round(pointA.getY() * yFactor));
        pointB = new Point2D.Double(Math.round(pointB.getX() * xFactor), Math.round(pointB.getY() * yFactor));
        pointC = new Point2D.Double(Math.round(pointC.getX() * xFactor), Math.round(pointC.getY() * yFactor));
        pointD = new Point2D.Double(Math.round(pointD.getX() * xFactor), Math.round(pointD.getY() * yFactor));
    } else {
        pt = new Point2D.Double(Math.round(dispB.getX() * xFactor), Math.round(dispB.getY() * yFactor));
        dispB = pt;
        pt = new Point2D.Double(Math.round(dispC.getX() * xFactor), Math.round(dispC.getY() * yFactor));
        dispC = pt;
    }
}
Also used : Point2D(java.awt.geom.Point2D)

Example 65 with Point2D

use of java.awt.geom.Point2D in project JMRI by JMRI.

the class LayoutTurnout method setCoordsCenter.

/**
     * Modify coordinates methods
     */
public void setCoordsCenter(Point2D p) {
    if (version == 2) {
        Point2D oldC = center;
        double offsety = oldC.getY() - p.getY();
        double offsetx = oldC.getX() - p.getX();
        pointA = new Point2D.Double(pointA.getX() - offsetx, pointA.getY() - offsety);
        pointB = new Point2D.Double(pointB.getX() - offsetx, pointB.getY() - offsety);
        pointC = new Point2D.Double(pointC.getX() - offsetx, pointC.getY() - offsety);
        pointD = new Point2D.Double(pointD.getX() - offsetx, pointD.getY() - offsety);
    }
    center = p;
}
Also used : Point2D(java.awt.geom.Point2D)

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