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

The following examples show how to use javax.vecmath.Point2d#distance() . 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: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the atom of the given molecule that is closest to the given atom
 * (excluding itself).
 *
 * @param atomCon The molecule that is searched for the closest atom
 * @param atom The atom to search around
 * @return The atom that is closest to the given coordinates
 */
public static IAtom getClosestAtom(IAtomContainer atomCon, IAtom atom) {
    IAtom closestAtom = null;
    double min = Double.MAX_VALUE;
    Point2d atomPosition = atom.getPoint2d();
    for (int i = 0; i < atomCon.getAtomCount(); i++) {
        IAtom currentAtom = atomCon.getAtom(i);
        if (!currentAtom.equals(atom)) {
            double d = atomPosition.distance(currentAtom.getPoint2d());
            if (d < min) {
                min = d;
                closestAtom = currentAtom;
            }
        }
    }
    return closestAtom;
}
 
Example 3
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Sorts a Vector of atoms such that the 2D distances of the atom locations
 * from a given point are smallest for the first atoms in the vector. See
 * comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param point The point from which the distances to the atoms are measured
 * @param atoms The atoms for which the distances to point are measured
 */
public static void sortBy2DDistance(IAtom[] atoms, Point2d point) {
    double distance1;
    double distance2;
    IAtom atom1;
    IAtom atom2;
    boolean doneSomething;
    do {
        doneSomething = false;
        for (int f = 0; f < atoms.length - 1; f++) {
            atom1 = atoms[f];
            atom2 = atoms[f + 1];
            distance1 = point.distance(atom1.getPoint2d());
            distance2 = point.distance(atom2.getPoint2d());
            if (distance2 < distance1) {
                atoms[f] = atom2;
                atoms[f + 1] = atom1;
                doneSomething = true;
            }
        }
    } while (doneSomething);
}
 
Example 4
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 5
Source File: GeometryTools.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the geometric length of this bond in 2D space. See comment for
 * center(IAtomContainer atomCon, Dimension areaDim, HashMap
 * renderingCoordinates) for details on coordinate sets
 *
 * @param bond Description of the Parameter
 * @return The geometric length of this bond
 */
public static double getLength2D(IBond bond) {
    if (bond.getBegin() == null || bond.getEnd() == null) {
        return 0.0;
    }
    Point2d point1 = bond.getBegin().getPoint2d();
    Point2d point2 = bond.getEnd().getPoint2d();
    if (point1 == null || point2 == null) {
        return 0.0;
    }
    return point1.distance(point2);
}
 
Example 6
Source File: MoleculeAligner.java    From ReactionDecoder with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
     *
     * @param atomContainer
     * @return
     */
    public static Vector2d getMaxWidthVector(IAtomContainer atomContainer) {
        int nAtoms = atomContainer.getAtomCount();
        Vector2d widthVector = null;
        IAtom maxI = null;
        IAtom maxJ = null;
        double maxDistance = 0;
        for (int indexI = nAtoms - 1; indexI >= 0; indexI--) {
            IAtom atomI = atomContainer.getAtom(indexI);
            Point2d pointI = atomI.getPoint2d();
            if (pointI == null) {
                continue;
            }
            for (int indexJ = indexI - 1; indexJ >= 0; indexJ--) {
                IAtom atomJ = atomContainer.getAtom(indexJ);
                Point2d pointJ = atomJ.getPoint2d();
                if (pointJ == null) {
                    continue;
                }
                double distance = pointI.distance(pointJ);
                if (distance > maxDistance) {
                    maxDistance = distance;
                    maxI = atomI;
                    maxJ = atomJ;
                }
            }
        }
//        System.out.println("maxI = " + atomContainer.getAtomNumber(maxI)
//                         + "maxJ = " + atomContainer.getAtomNumber(maxJ));
        if (maxI != null && maxJ != null) {
            widthVector = new Vector2d(maxI.getPoint2d());
            widthVector.sub(maxJ.getPoint2d());
        } else {
            return new Vector2d(0, 0);
        }
        return widthVector;
    }
 
Example 7
Source File: ConvexHull.java    From ReactionDecoder with GNU Lesser General Public License v3.0 4 votes vote down vote up
private double pointLineDistance(Point2d p1, Point2d p2, Point2d p3) {
    Point2d p = project(p1, p2, p3);
    return p3.distance(p);
}