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);
}
}
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;
}
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)));
}
}
}
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;
}
}
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;
}
Aggregations