private void drawOffsetBond(Point2d p1, Point2d p2, Point2d c, Graphics2D g) { double distanceProportion = params.offsetBondDistanceProportion; Point2d w = new Point2d(); w.interpolate(c, p1, distanceProportion); Point2d u = new Point2d(); u.interpolate(c, p2, distanceProportion); drawLine(w, u, g); }
private void drawOffsetBond(Point2d p1, Point2d p2, Point2d c, Graphics2D g) { double distanceProportion = this.params.offsetBondDistanceProportion; Point2d w = new Point2d(); w.interpolate((Tuple2d) c, (Tuple2d) p1, distanceProportion); Point2d u = new Point2d(); u.interpolate((Tuple2d) c, (Tuple2d) p2, distanceProportion); this.drawLine(w, u, g); }
public void drawDashedWedge(Point2d a, Point2d b, Point2d c, Graphics2D g) { Stroke savedStroke = g.getStroke(); g.setStroke(this.dashedWedgeStroke); double distance = b.distance(a); double gapFactor = this.params.dashedGapFactor; double gap = distance * gapFactor; double numberOfDashes = distance / gap; double d = 0.0; int i = 0; while ((double) i < numberOfDashes) { Point2d p1 = new Point2d(); p1.interpolate((Tuple2d) a, (Tuple2d) b, d); Point2d p2 = new Point2d(); p2.interpolate((Tuple2d) a, (Tuple2d) c, d); this.drawLine(p1, p2, g); if (distance * (d + gapFactor) >= distance) { break; } d += gapFactor; ++i; } g.setStroke(savedStroke); }
private void drawDashedWedge(Point2d vertexA, Point2d vertexB, Point2d vertexC) { // store the current stroke Stroke storedStroke = this.graphics.getStroke(); this.graphics.setStroke(new BasicStroke(1)); // calculate the distances between lines double distance = vertexB.distance(vertexA); double gapFactor = 0.1; double gap = distance * gapFactor; double numberOfDashes = distance / gap; double displacement = 0; // draw by interpolating along the edges of the triangle for (int i = 0; i < numberOfDashes; i++) { Point2d point1 = new Point2d(); point1.interpolate(vertexA, vertexB, displacement); Point2d point2 = new Point2d(); point2.interpolate(vertexA, vertexC, displacement); int[] p1T = this.transformPoint(point1.x, point1.y); int[] p2T = this.transformPoint(point2.x, point2.y); this.graphics.drawLine(p1T[0], p1T[1], p2T[0], p2T[1]); if (distance * (displacement + gapFactor) >= distance) { break; } else { displacement += gapFactor; } } this.graphics.setStroke(storedStroke); }
point1.interpolate(vertexA, vertexB, displacement); int[] p1T = this.transformPoint(point1.x, point1.y); displacement += gapFactor; Point2d point2 = new Point2d(); if (flip) { point2.interpolate(vertexA, vertexC, displacement); } else { point2.interpolate(vertexA, vertexB, displacement);
p1.interpolate(vertexA, vertexB, d); Point2d p2 = new Point2d(); p2.interpolate(vertexA, vertexC, d); int[] p1T = this.transformPoint(p1.x, p1.y); int[] p2T = this.transformPoint(p2.x, p2.y);
/** * * @param a * @param b * @param c * @param g */ public void drawDashedWedge(Point2d a, Point2d b, Point2d c, Graphics2D g) { Stroke savedStroke = g.getStroke(); g.setStroke(dashedWedgeStroke); double distance = b.distance(a); double gapFactor = params.dashedGapFactor; double gap = distance * gapFactor; double numberOfDashes = distance / gap; double d = 0; // draw by interpolating along the edges of the triangle for (int i = 0; i < numberOfDashes; i++) { Point2d p1 = new Point2d(); p1.interpolate(a, b, d); Point2d p2 = new Point2d(); p2.interpolate(a, c, d); drawLine(p1, p2, g); if (distance * (d + gapFactor) >= distance) { break; } else { d += gapFactor; } } g.setStroke(savedStroke); }
double d2 = d-gapFactor; Point2d p1 = new Point2d(); p1.interpolate(vertexA, vertexB, d); Point2d p2 = new Point2d(); p2.interpolate(vertexA, vertexC, d2); int[] p1T = this.transformPoint(p1.x, p1.y); int[] p2T = this.transformPoint(p2.x, p2.y);
p1.interpolate(vertexA, vertexB, d); Point2d p2 = new Point2d(); p2.interpolate(vertexA, vertexC, d); double[] p1T = this.transformPoint(p1.x, p1.y); double[] p2T = this.transformPoint(p2.x, p2.y);
double d2 = d-gapFactor; Point2d p1 = new Point2d(); p1.interpolate(vertexA, vertexB, d); Point2d p2 = new Point2d(); p2.interpolate(vertexA, vertexC, d2); double[] p1T = this.transformPoint(p1.x, p1.y); double[] p2T = this.transformPoint(p2.x, p2.y);
g.setColor(Color.BLACK); Point2d midPoint = new Point2d(prev); midPoint.interpolate((Tuple2d) hullPoint, 0.5); Vector2d direction = new Vector2d((Tuple2d) hullPoint); direction.sub((Tuple2d) prev); g.setColor(Color.BLACK); Point2d midPoint = new Point2d(prev); midPoint.interpolate((Tuple2d) first, 0.5); Vector2d direction = new Vector2d((Tuple2d) first); direction.sub((Tuple2d) prev);
/** * Make the inner ring bond, which is slightly shorter than the outer bond. * * @param bond the ring bond * @param ring the ring that the bond is in * @param model the renderer model * @return the line element */ public LineElement generateInnerElement(IBond bond, IRing ring, RendererModel model) { Point2d center = GeometryUtil.get2DCenter(ring); Point2d a = bond.getBegin().getPoint2d(); Point2d b = bond.getEnd().getPoint2d(); // the proportion to move in towards the ring center double distanceFactor = model.getParameter(TowardsRingCenterProportion.class).getValue(); double ringDistance = distanceFactor * IDEAL_RINGSIZE / ring.getAtomCount(); if (ringDistance < distanceFactor / MIN_RINGSIZE_FACTOR) ringDistance = distanceFactor / MIN_RINGSIZE_FACTOR; Point2d w = new Point2d(); w.interpolate(a, center, ringDistance); Point2d u = new Point2d(); u.interpolate(b, center, ringDistance); double alpha = 0.2; Point2d ww = new Point2d(); ww.interpolate(w, u, alpha); Point2d uu = new Point2d(); uu.interpolate(u, w, alpha); double width = getWidthForBond(bond, model); Color color = getColorForBond(bond, model); return new LineElement(u.x, u.y, w.x, w.y, width, color); }
double currentDistance = 0.0; Point2d d = new Point2d(b); d.interpolate((Tuple2d) c, 0.5); Vector2d perp = this.makePerpendicular(a, d); Vector2d nPerp = new Vector2d(perp); while ((double) i < numberOfDashes) { Point2d rungCenter = new Point2d(a); rungCenter.interpolate((Tuple2d) d, currentDistance); Point2d p1 = new Point2d(rungCenter); p1.scaleAdd(currentWidth, (Tuple2d) perp, (Tuple2d) p1);
/** * Computes the perpendicular bisector of line segment defined by its two endpoints. * The bisector starts off the the middle of the line segment and points toward the left side of the line segment. * <p> * Edge cases: * <ul> * <li> when the line segment endpoints are equal, * more precisely when {@code lineSegmentStart.distance(lineSegmentEnd) < Epsilons.ONE_TRILLIONTH}, * the method fails and returns {@code false}. * </ul> * </p> * * @param lineSegmentStart the first endpoint of the line segment. Not modified. * @param lineSegmentEnd the second endpoint of the line segment. Not modified. * @param bisectorStartToPack a 2D point in which the origin of the bisector is stored. Modified. * @param bisectorDirectionToPack a 2D vector in which the direction of the bisector is stored. Modified. * @return whether the perpendicular bisector could be determined or not. */ public static boolean getPerpendicularBisector(Point2d lineSegmentStart, Point2d lineSegmentEnd, Point2d bisectorStartToPack, Vector2d bisectorDirectionToPack) { if (lineSegmentStart.distance(lineSegmentEnd) < Epsilons.ONE_TRILLIONTH) return false; // direction will be on left side of line bisectorStartToPack.interpolate(lineSegmentStart, lineSegmentEnd, 0.5); bisectorDirectionToPack.sub(lineSegmentEnd, lineSegmentStart); getPerpendicularVector(bisectorDirectionToPack, bisectorDirectionToPack); bisectorDirectionToPack.normalize(); return true; }
double currentDistance = 0; Point2d d = new Point2d(b); d.interpolate(c, 0.5); Vector2d perp = makePerpendicular(a, d); Vector2d nPerp = new Vector2d(perp); rungCenter.interpolate(d, currentDistance);
p1.interpolate(vertexA, vertexB, d); Point2d p2 = new Point2d(); p2.interpolate(vertexA, vertexB, d+1/numberOfCircles);
public void draw(CanvasGenerator canvasGenerator, Graphics2D g) { for (Arrow arrow : this.arrows) { Rectangle2D tailCanvas = canvasGenerator.getCanvasForAtomContainer(arrow.tail); Rectangle2D headCanvas = canvasGenerator.getCanvasForAtomContainer(arrow.head); Point2d tailCenter = new Point2d(tailCanvas.getCenterX(), tailCanvas.getCenterY()); Point2d headCenter = new Point2d(headCanvas.getCenterX(), headCanvas.getCenterY()); arrow.center = new Point2d(tailCenter); arrow.center.interpolate((Tuple2d) headCenter, 0.5); arrow.vector = new Vector2d((Tuple2d) headCenter); arrow.vector.sub((Tuple2d) tailCenter); arrow.vector.normalize(); } int i = 0; for (Arrow arrow2 : this.arrows) { this.arrowDrawer.drawThinArrow(g, arrow2.center, arrow2.vector, this.arrowLabels.get(i)); ++i; } }
headCanvas.getCenterX(), headCanvas.getCenterY()); arrow.center = new Point2d(tailCenter); arrow.center.interpolate(headCenter, 0.5);
private void drawBondChangeMarks(List<IBond> bondsChanged, Graphics2D g) { double markLength = params.bondMarkLength; for (IBond bond : bondsChanged) { Point2d p1 = bond.getAtom(0).getPoint2d(); Point2d p2 = bond.getAtom(1).getPoint2d(); Point2d center = new Point2d(p1); center.interpolate(p2, 0.5); Vector2d bondVector = new Vector2d(p1); bondVector.sub(p2); bondVector.normalize(); Vector2d perp = new Vector2d(-bondVector.y, bondVector.x); Vector2d negPerp = new Vector2d(perp); negPerp.negate(); Point2d pp1 = new Point2d(center); pp1.scaleAdd(markLength / 2, perp, pp1); Point2d pp2 = new Point2d(center); pp2.scaleAdd(markLength / 2, negPerp, pp2); drawLine(pp1, pp2, g); } }
Point2d p2 = bond.getAtom(1).getPoint2d(); Point2d center = new Point2d(p1); center.interpolate(p2, 0.5);