Search in sources :

Example 1 with AxisAlignedBoundingBox

use of org.twak.viewTrace.QuadTree.AxisAlignedBoundingBox in project chordatlas by twak.

the class GBias method getAngle.

/**
 * local bias
 */
public Double getAngle(Line line, Point2d cen) {
    final double PI8 = Math.PI / 8;
    DRectangle r = new DRectangle(line);
    r.grow(expand);
    Collection<Longer> res = tree.queryRange(r);
    double bestScore = -Double.MAX_VALUE;
    Double bestAngle = null;
    for (AxisAlignedBoundingBox aabb : res) {
        Line gis = ((Longer) aabb).line;
        double len = gis.length();
        // gis.distance( line );
        double dist = gis.fromPPram(0.5).distance(line.fromPPram(0.5));
        if (dist < len * expand) {
            double angle = line.absAngle(gis);
            if (angle < PI8) {
                double score = (PI8 - angle) / dist;
                if (score > bestScore) {
                    bestAngle = gis.aTan2();
                    bestScore = score;
                }
            } else if (Mathz.inRangeTol(angle, Mathz.PI2, PI8)) {
                double score = 0.2 * (PI8 - angle) / dist;
                if (score > bestScore) {
                    gis = new Line(new Point2d(gis.start.y, -gis.start.x), new Point2d(gis.end.y, -gis.end.x));
                    if (gis.absAngle(line) > PI8)
                        gis = gis.reverse();
                    bestAngle = gis.aTan2();
                    bestScore = score;
                }
            }
        }
    }
    if (bestAngle != null)
        return bestAngle;
    else
        return null;
}
Also used : Line(org.twak.utils.Line) QLine(org.twak.viewTrace.QuadTree.QLine) AxisAlignedBoundingBox(org.twak.viewTrace.QuadTree.AxisAlignedBoundingBox) DRectangle(org.twak.utils.geom.DRectangle) Point2d(javax.vecmath.Point2d)

Aggregations

Point2d (javax.vecmath.Point2d)1 Line (org.twak.utils.Line)1 DRectangle (org.twak.utils.geom.DRectangle)1 AxisAlignedBoundingBox (org.twak.viewTrace.QuadTree.AxisAlignedBoundingBox)1 QLine (org.twak.viewTrace.QuadTree.QLine)1