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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations