Search in sources :

Example 56 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class CutHoles method cutHoles.

public static void cutHoles(LoopL<Point2d> out, double tol, Map<Point2d, Line> created) {
    MultiMap<Boolean, Loop<Point2d>> holeToLoop = new MultiMap<>();
    Iterator<Loop<Point2d>> lit = out.iterator();
    while (lit.hasNext()) {
        // a hole can be a backwards loop...
        Loop<Point2d> loop = lit.next();
        double area = Loopz.area(loop);
        if (Math.abs(area) < tol * tol)
            lit.remove();
        boolean isHole = area > 0;
        holeToLoop.put(isHole, loop);
        for (Loop<Point2d> h : loop.holes) {
            if (Loopz.area(h) > 0)
                h.reverse();
            holeToLoop.put(false, h);
        }
    }
    for (Loop<Point2d> hole : holeToLoop.get(false)) {
        Point2d origin = new Point2d(Double.MAX_VALUE, 0);
        Loopable<Point2d> originL = null;
        for (Loopable<Point2d> p : hole.loopableIterator()) {
            if (p.get().x < origin.x) {
                originL = p;
                origin = originL.get();
            }
        }
        LinearForm ray = new LinearForm(0, 1);
        ray.findC(origin);
        double nearestD = Double.MAX_VALUE;
        Loopable<Point2d> nearestL = null;
        Point2d nearestH = null;
        for (Loop<Point2d> loop : out) {
            for (Loopable<Point2d> line : loop.loopableIterator()) {
                Point2d a = line.get(), b = line.getNext().get();
                if (a.y > origin.y && b.y < origin.y || a.y < origin.y && b.y > origin.y) {
                    Point2d hit = new Line(a, b).intersects(ray);
                    if (hit != null && hit.x < origin.x && (origin.x - hit.x < nearestD)) {
                        nearestD = origin.x - hit.x;
                        nearestL = line;
                        nearestH = hit;
                    }
                }
            }
        }
        if (nearestH == null)
            System.err.println("failed to find outer ring for hole");
        else {
            if (created != null)
                created.put(nearestH, new Line(nearestL.get(), nearestL.getNext().get()));
            Loopable<Point2d> hitPtF = new Loopable<Point2d>(nearestH), hitPtS = new Loopable<Point2d>(nearestH), originL2 = new Loopable(origin);
            hitPtS.setNext(nearestL.getNext());
            hitPtF.setPrev(nearestL);
            hitPtS.getNext().setPrev(hitPtS);
            hitPtF.getPrev().setNext(hitPtF);
            originL.getNext().setPrev(originL2);
            originL2.setNext(originL.getNext());
            originL.setNext(hitPtS);
            hitPtS.setPrev(originL);
            hitPtF.setNext(originL2);
            originL2.setPrev(hitPtF);
        }
        out.remove(hole);
    }
}
Also used : Loop(org.twak.utils.collections.Loop) LinearForm(org.twak.utils.geom.LinearForm) Line(org.twak.utils.Line) Loopable(org.twak.utils.collections.Loopable) MultiMap(org.twak.utils.collections.MultiMap) Point2d(javax.vecmath.Point2d)

Example 57 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class FacadeFinder method adjacentDist.

public double adjacentDist(Line l, Point2d pt) {
    Vector2d v1 = new Vector2d(l.end);
    v1.sub(l.start);
    Vector2d v2 = new Vector2d(pt);
    v2.sub(l.start);
    double param = v2.dot(v1) / v1.length();
    if (param < 0 || param > v1.length())
        return Double.MAX_VALUE;
    v1.normalize();
    v1.scale(param);
    v1.add(l.start);
    return new Point2d(v1).distance(pt);
}
Also used : Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d)

Example 58 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class FacadeFinder method guessHeight.

private double guessHeight(List<Point3d> meshPoints, Line l) {
    double height;
    height = 2;
    for (Point3d pt : meshPoints) {
        if (adjacentDist(l, new Point2d(pt.x, pt.z)) < 2)
            height = Math.max(height, pt.y);
    }
    return height;
}
Also used : Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d)

Example 59 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class Concarnie method findSupporting.

private Line findSupporting(Loopable<Point2d> pt, int dir) {
    double totalDist = 0;
    Point2d ptg = pt.get();
    Loopable<Point2d> current = pt;
    int count = 0;
    do {
        Point2d a = current.get(), b = current.move(dir).get();
        if (dir < 0) {
            Point2d tmp = a;
            a = b;
            b = tmp;
        }
        Line hull = new Line(a, b);
        double bestDist = Double.MAX_VALUE;
        Line bestLine = null;
        for (Line l : new ItComb<>(in.getNear(hull.start, 0.5), in.getNear(hull.end, 0.5))) if (Anglez.dist(l.aTan2(), hull.aTan2()) < 0.2 && maxPerpDistance(l, hull) < 0.2) {
            double dist = l.distance(ptg, true);
            if (dist < bestDist) {
                bestDist = dist;
                bestLine = l;
            }
        }
        if (bestLine != null)
            return bestLine;
        totalDist += hull.length();
        current = current.move(dir);
    } while (totalDist < 1 && count++ < 30);
    return null;
}
Also used : Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ItComb(org.twak.utils.collections.ItComb) Paint(java.awt.Paint)

Example 60 with Point2d

use of javax.vecmath.Point2d in project chordatlas by twak.

the class Concarnie method signedArea.

private double signedArea(Collection<Line> set) {
    double ax = set.stream().collect(Collectors.averagingDouble(l -> l.start.x)).doubleValue(), ay = set.stream().collect(Collectors.averagingDouble(l -> l.start.y)).doubleValue();
    Point2d cen = new Point2d(ax, ay);
    double c = set.stream().collect(Collectors.summingDouble(x -> Mathz.area(cen, x.end, x.start))).doubleValue();
    return c;
}
Also used : Point2d(javax.vecmath.Point2d)

Aggregations

Point2d (javax.vecmath.Point2d)84 Line (org.twak.utils.Line)37 ArrayList (java.util.ArrayList)29 Point3d (javax.vecmath.Point3d)27 List (java.util.List)18 Vector2d (javax.vecmath.Vector2d)17 SuperLine (org.twak.viewTrace.SuperLine)17 File (java.io.File)15 Vector3d (javax.vecmath.Vector3d)15 Map (java.util.Map)14 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)14 HashMap (java.util.HashMap)13 Loop (org.twak.utils.collections.Loop)13 Collectors (java.util.stream.Collectors)12 IOException (java.io.IOException)11 HashSet (java.util.HashSet)11 Set (java.util.Set)11 Tweed (org.twak.tweed.Tweed)11 Matrix4d (javax.vecmath.Matrix4d)10 LinearForm (org.twak.utils.geom.LinearForm)10