List of usage examples for java.awt.geom Line2D getY1
public abstract double getY1();
From source file:Polygon2D.java
public Polyline2D(Line2D line) { npoints = 2;/*from w w w . j a v a 2 s . c o m*/ xpoints = new float[2]; ypoints = new float[2]; xpoints[0] = (float) line.getX1(); xpoints[1] = (float) line.getX2(); ypoints[0] = (float) line.getY1(); ypoints[1] = (float) line.getY2(); calculatePath(); }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * divide a Line2D into 2 new Line2Ds that are returned * in the passed left and right instances, if non-null * @param src the line to divide/*from w w w. j a va 2 s .c o m*/ * @param left the left side, or null * @param right the right side, or null */ protected void subdivide(Line2D src, Line2D left, Line2D right) { double x1 = src.getX1(); double y1 = src.getY1(); double x2 = src.getX2(); double y2 = src.getY2(); double mx = x1 + (x2 - x1) / 2.0; double my = y1 + (y2 - y1) / 2.0; if (left != null) { left.setLine(x1, y1, mx, my); } if (right != null) { right.setLine(mx, my, x2, y2); } }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * This is used for the arrow of a directed and for one of the * arrows for non-directed edges/*from w ww . j ava 2 s .c om*/ * Get a transform to place the arrow shape on the passed edge at the * point where it intersects the passed shape * @param edgeShape * @param vertexShape * @return */ public AffineTransform getArrowTransform(Line2D edgeShape, Shape vertexShape) { float dx = (float) (edgeShape.getX1() - edgeShape.getX2()); float dy = (float) (edgeShape.getY1() - edgeShape.getY2()); // iterate over the line until the edge shape will place the // arrowhead closer than 'arrowGap' to the vertex shape boundary while ((dx * dx + dy * dy) > arrow_placement_tolerance) { try { edgeShape = getLastOutsideSegment(edgeShape, vertexShape); } catch (IllegalArgumentException e) { System.err.println(e.toString()); return null; } dx = (float) (edgeShape.getX1() - edgeShape.getX2()); dy = (float) (edgeShape.getY1() - edgeShape.getY2()); } double atheta = Math.atan2(dx, dy) + Math.PI / 2; AffineTransform at = AffineTransform.getTranslateInstance(edgeShape.getX1(), edgeShape.getY1()); at.rotate(-atheta); return at; }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * This is used for the reverse-arrow of a non-directed edge * get a transform to place the arrow shape on the passed edge at the * point where it intersects the passed shape * @param edgeShape//from w w w . j a v a 2 s. co m * @param vertexShape * @return */ protected AffineTransform getReverseArrowTransform(Line2D edgeShape, Shape vertexShape) { float dx = (float) (edgeShape.getX1() - edgeShape.getX2()); float dy = (float) (edgeShape.getY1() - edgeShape.getY2()); // iterate over the line until the edge shape will place the // arrowhead closer than 'arrowGap' to the vertex shape boundary while ((dx * dx + dy * dy) > arrow_placement_tolerance) { try { edgeShape = getFirstOutsideSegment(edgeShape, vertexShape); } catch (IllegalArgumentException e) { System.err.println(e.toString()); return null; } dx = (float) (edgeShape.getX1() - edgeShape.getX2()); dy = (float) (edgeShape.getY1() - edgeShape.getY2()); } // calculate the angle for the arrowhead double atheta = Math.atan2(dx, dy) - Math.PI / 2; AffineTransform at = AffineTransform.getTranslateInstance(edgeShape.getX1(), edgeShape.getY1()); at.rotate(-atheta); return at; }
From source file:biogenesis.Organism.java
/** * Calculates the resulting speeds after a collision between two organisms, following * physical rules./* w ww. ja va2 s . co m*/ * * @param org The other organism in the collision. * @param p Intersection point between the organisms. * @param l Line that has collided. Of the two lines, this is the one that collided * on the center, not on the vertex. * @param thisOrganism true if l is a line of this organism, false if l is a line of org. */ private void touchMove(Organism org, Point2D.Double p, Line2D l, boolean thisOrganism) { // Distance vector between centers of mass and p double rapx = p.x - _dCenterX; double rapy = p.y - _dCenterY; double rbpx = p.x - org._dCenterX; double rbpy = p.y - org._dCenterY; // Speeds of point p in the body A and B, before collision. double vap1x = dx - dtheta * rapy + hasGrown * rapx / 10d; double vap1y = dy + dtheta * rapx + hasGrown * rapy / 10d; double vbp1x = org.dx - org.dtheta * rbpy; double vbp1y = org.dy + org.dtheta * rbpx; // Relative speeds between the two collision points. double vab1x = vap1x - vbp1x; double vab1y = vap1y - vbp1y; // Normal vector to the impact line //First: perpendicular vector to the line double nx = l.getY1() - l.getY2(); double ny = l.getX2() - l.getX1(); //Second: normalize, modulus 1 double modn = Math.sqrt(nx * nx + ny * ny); nx /= modn; ny /= modn; /*Third: of the two possible normal vectors we need the one that points to the * outside; we choose the one that its final point is the nearest to the center * of the other line. */ if (thisOrganism) { if ((p.x + nx - org._dCenterX) * (p.x + nx - org._dCenterX) + (p.y + ny - org._dCenterY) * (p.y + ny - org._dCenterY) < (p.x - nx - org._dCenterX) * (p.x - nx - org._dCenterX) + (p.y - ny - org._dCenterY) * (p.y - ny - org._dCenterY)) { nx = -nx; ny = -ny; } } else { if ((p.x + nx - _dCenterX) * (p.x + nx - _dCenterX) + (p.y + ny - _dCenterY) * (p.y + ny - _dCenterY) > (p.x - nx - _dCenterX) * (p.x - nx - _dCenterX) + (p.y - ny - _dCenterY) * (p.y - ny - _dCenterY)) { nx = -nx; ny = -ny; } } // This is the j in the parallel axis theorem double j = (-(1 + Utils.ELASTICITY) * (vab1x * nx + vab1y * ny)) / (1 / _mass + 1 / org._mass + Math.pow(rapx * ny - rapy * nx, 2) / _I + Math.pow(rbpx * ny - rbpy * nx, 2) / org._I); // Final speed dx = Utils.between(dx + j * nx / _mass, -Utils.MAX_VEL, Utils.MAX_VEL); dy = Utils.between(dy + j * ny / _mass, -Utils.MAX_VEL, Utils.MAX_VEL); org.dx = Utils.between(org.dx - j * nx / org._mass, -Utils.MAX_VEL, Utils.MAX_VEL); org.dy = Utils.between(org.dy - j * ny / org._mass, -Utils.MAX_VEL, Utils.MAX_VEL); dtheta = Utils.between(dtheta + j * (rapx * ny - rapy * nx) / _I, -Utils.MAX_ROT, Utils.MAX_ROT); org.dtheta = Utils.between(org.dtheta - j * (rbpx * ny - rbpy * ny) / org._I, -Utils.MAX_ROT, Utils.MAX_ROT); }
From source file:org.gumtree.vis.awt.JChartPanel.java
private Line2D convertDomainAxisMarker(Line2D marker) { Line2D newLine = (Line2D) marker.clone(); Rectangle2D imageArea = getScreenDataArea(); double maxY = imageArea.getBounds2D().getMaxY(); if (maxY == 0) { isShapeValid = false;//from w ww. j a va2 s. co m } newLine.setLine(marker.getX1(), ChartMaskingUtilities.translateScreenY(maxY - marker.getY1(), imageArea, getChart(), 0), marker.getX2(), ChartMaskingUtilities.translateScreenY(maxY - marker.getY2(), imageArea, getChart(), 0)); return newLine; }
From source file:org.gumtree.vis.awt.JChartPanel.java
private Line2D convertRangeAxisMarker(Line2D marker) { Line2D newLine = (Line2D) marker.clone(); Rectangle2D imageArea = getScreenDataArea(); double minX = imageArea.getBounds2D().getMinX(); if (imageArea.getBounds2D().getMaxX() == 0) { isShapeValid = false;//from w ww . ja v a2s .c om } newLine.setLine(ChartMaskingUtilities.translateScreenX(minX + marker.getX1(), imageArea, getChart()), marker.getY1(), ChartMaskingUtilities.translateScreenX(minX + marker.getX2(), imageArea, getChart()), marker.getY2()); return newLine; }