Java Code Examples for java.awt.geom.Line2D#ptLineDistSq()

The following examples show how to use java.awt.geom.Line2D#ptLineDistSq() . 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: FilamentAlignment.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public double getMeanDistance ()
{
    if (line == null) {
        computeLine();
    }

    if (meanDistance == null) {
        Line2D straight = new Line2D.Double(startPoint, stopPoint);

        double totalDistSq = 0;
        int pointCount = points.size() - 2; // Only intermediate points!

        for (int i = 1, iMax = pointCount; i <= iMax; i++) {
            totalDistSq += straight.ptLineDistSq(points.get(i));
        }

        if (pointCount > 0) {
            meanDistance = Math.sqrt(totalDistSq / pointCount);
        }
    }

    return (meanDistance != null) ? meanDistance : 0;
}
 
Example 2
Source File: LineUtil.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Computation of rotation from first to last point, with middle as approximate
 * middle point of the curve.
 *
 * @param line   straight line from curve start to curve stop
 * @param middle middle point of curve
 * @return central rotation angle (in radians) from curve start to curve stop.
 */
public static double rotation (Line2D line,
                               Point2D middle)
{
    double dx = line.getX2() - line.getX1();
    double dy = line.getY2() - line.getY1();
    double halfChordLengthSq = ((dx * dx) + (dy * dy)) / 4;
    double sagittaSq = line.ptLineDistSq(middle);

    return 4 * Math.atan(Math.sqrt(sagittaSq / halfChordLengthSq));
}
 
Example 3
Source File: LineWidget.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}
 
Example 4
Source File: LineWidget.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}
 
Example 5
Source File: LineWidget.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}
 
Example 6
Source File: LineWidget.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}
 
Example 7
Source File: LineWidget.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}
 
Example 8
Source File: LineWidget.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}
 
Example 9
Source File: LineWidget.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}
 
Example 10
Source File: LineWidget.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isHitAt(Point localPoint) {
    return Line2D.ptLineDistSq(from.x, from.y, to.x, to.y, localPoint.x, localPoint.y) <= BORDER * BORDER;
}