Java Code Examples for javax.vecmath.Point2d#interpolate()

The following examples show how to use javax.vecmath.Point2d#interpolate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 * @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);
}
 
Example 2
Source File: DirectRBLastReactionDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param a
 * @param b
 * @param c
 * @param g
 */
public void drawDashedWedge2(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 currentDistance = 0;
    Point2d d = new Point2d(b);
    d.interpolate(c, 0.5);
    Vector2d perp = makePerpendicular(a, d);
    Vector2d nPerp = new Vector2d(perp);
    nPerp.negate();
    double maxWidth = params.dashedWedgeWidth / 4;
    double currentWidth = maxWidth * params.dashedWidthFactor;
    // draw like a ladder with increasing rung length
    for (int i = 0; i < numberOfDashes; i++) {
        Point2d rungCenter = new Point2d(a);
        rungCenter.interpolate(d, currentDistance);

        Point2d p1 = new Point2d(rungCenter);
        p1.scaleAdd(currentWidth, perp, p1);

        Point2d p2 = new Point2d(rungCenter);
        p2.scaleAdd(currentWidth, nPerp, p2);

        drawLine(p1, p2, g);
        if (distance * (currentDistance + gapFactor) >= distance) {
            break;
        } else {
            currentDistance += gapFactor;
            currentWidth += maxWidth * (params.dashedWidthFactor);
        }
    }
    g.setStroke(savedStroke);
}
 
Example 4
Source File: DirectBondDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: DirectRBLastReactionDrawer.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void drawBondExistentialMarks(List<IBond> bondsCleaved, Graphics2D g) {
    double markLength = params.bondMarkLength;
    for (IBond bond : bondsCleaved) {
        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 negBondVector = new Vector2d(bondVector);
        negBondVector.negate();

        Point2d pc1 = new Point2d(center);
        pc1.scaleAdd(params.doubleMarkGap, bondVector, pc1);

        Point2d pc2 = new Point2d(center);
        pc2.scaleAdd(params.doubleMarkGap, negBondVector, pc2);

        Vector2d perp = new Vector2d(-bondVector.y, bondVector.x);
        Vector2d negPerp = new Vector2d(perp);
        negPerp.negate();

        Point2d pp11 = new Point2d(pc1);
        pp11.scaleAdd(markLength / 2, perp, pp11);
        Point2d pp12 = new Point2d(pc1);
        pp12.scaleAdd(markLength / 2, negPerp, pp12);

        drawLine(pp11, pp12, g);

        Point2d pp21 = new Point2d(pc2);
        pp21.scaleAdd(markLength / 2, perp, pp21);
        Point2d pp22 = new Point2d(pc2);
        pp22.scaleAdd(markLength / 2, negPerp, pp22);

        drawLine(pp21, pp22, g);
    }
}