use of javax.vecmath.Vector2d 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.Vector2d in project chordatlas by twak.
the class FindLines method rotateToAngle.
public static Line rotateToAngle(Line nLine, Point2d cen, double angle) {
double len = nLine.length() / 2;
Vector2d dir = new Vector2d(-Math.cos(angle) * len, -Math.sin(angle) * len);
Point2d start = new Point2d(cen), end = new Point2d(cen);
start.add(dir);
end.sub(dir);
return new Line(start, end);
}
use of javax.vecmath.Vector2d in project chordatlas by twak.
the class GreebleGrid method moulding.
protected void moulding(Matrix4d to3d, DRectangle rect, MeshBuilder mb) {
double hh = rect.height / 2;
Point3d start = new Point3d(rect.x, 0, rect.y + hh), end = new Point3d(rect.getMaxX(), 0, rect.y + hh);
to3d.transform(start);
to3d.transform(end);
Line3d line = new Line3d(start, end);
Vector3d dir = line.dir();
dir.normalize();
Vector3d nDir = new Vector3d(dir);
nDir.scale(-1);
LinearForm3D left = new LinearForm3D(nDir, start), right = new LinearForm3D(dir, end);
LinearForm3D wall = new LinearForm3D(to3d.m01, to3d.m11, to3d.m21);
wall.findD(start);
Tube.tube(mb, Collections.singleton(left), Collections.singleton(right), line, wall, wall, new CrossGen() {
@Override
public List<Point2d> gen(Vector2d down, Vector2d up) {
Vector2d d = new Vector2d(down);
d.normalize();
Vector2d dP = new Vector2d(d.y, -d.x);
List<Point2d> out = new ArrayList();
for (double[] coords : new double[][] { { 1.00, 0.00 }, { 1.00, 0.05 }, { 0.66, 0.05 }, { 0.66, 0.10 }, { 0.33, 0.10 }, { 0.33, 0.17 }, { 0.00, 0.17 }, { 0.00, 0.00 } }) {
Point2d tmp = new Point2d(d);
tmp.scale(coords[0] * rect.height - hh);
Point2d tmp2 = new Point2d(dP);
tmp2.scale(coords[1]);
tmp.add(tmp2);
out.add(tmp);
}
return out;
}
});
}
use of javax.vecmath.Vector2d in project chordatlas by twak.
the class Prof method renderStrip.
public Mesh renderStrip(double width, Point3d point3d) {
Mesh m = new Mesh();
m.setMode(Mesh.Mode.Triangles);
List<Float> coords = new ArrayList();
List<Integer> inds = new ArrayList();
Vector3d perp = new Vector3d(dir);
perp.scale(width / 2);
Point3d delta = new Point3d();
if (point3d != null) {
delta.set(point3d);
delta.sub(to3d(get(0)));
}
for (Pair<Point3d, Point3d> p : new ConsecutiveItPairs<>(get3D())) {
int o = coords.size() / 3;
inds.add(o + 0);
inds.add(o + 1);
inds.add(o + 2);
inds.add(o + 2);
inds.add(o + 1);
inds.add(o + 0);
inds.add(o + 1);
inds.add(o + 3);
inds.add(o + 2);
inds.add(o + 2);
inds.add(o + 3);
inds.add(o + 1);
Point3d a1 = new Point3d(p.first()), a2 = new Point3d(p.first()), b1 = new Point3d(p.second()), b2 = new Point3d(p.second());
a1.add(delta);
a2.add(delta);
b1.add(delta);
b2.add(delta);
a1.sub(perp);
a2.add(perp);
b1.sub(perp);
b2.add(perp);
for (Point3d pt : new Point3d[] { a1, a2, b1, b2 }) {
coords.add((float) pt.x);
coords.add((float) pt.y);
coords.add((float) pt.z);
}
}
{
Point3d p1 = to3d(get(size() - 1)), p2 = to3d(get(size() - 1));
Point2d arrowT = new Point2d(get(size() - 1)), arrowB = null;
for (int e = size() - 2; e >= 0; e--) if (!get(e).equals(get(size() - 1))) {
arrowB = new Point2d(get(e));
break;
}
if (arrowB != null) {
arrowT.sub(arrowB);
arrowT.scale(width * 1.3 / new Vector2d(arrowT).length());
arrowT.add(get(size() - 1));
Point3d p3 = to3d(arrowT);
p1.add(perp);
p2.sub(perp);
p1.add(delta);
p2.add(delta);
p3.add(delta);
int o = coords.size() / 3;
inds.add(o + 0);
inds.add(o + 1);
inds.add(o + 2);
inds.add(o + 2);
inds.add(o + 1);
inds.add(o + 0);
for (Point3d pt : new Point3d[] { p1, p2, p3 }) {
coords.add((float) pt.x);
coords.add((float) pt.y);
coords.add((float) pt.z);
}
}
}
m.setBuffer(VertexBuffer.Type.Position, 3, Arrayz.toFloatArray(coords));
m.setBuffer(VertexBuffer.Type.Index, 2, Arrayz.toIntArray(inds));
return m;
}
use of javax.vecmath.Vector2d in project chordatlas by twak.
the class Prof method parameterize.
public Prof parameterize() {
// find and subtract vertical lines
Set<Line> lines = new HashSet<>();
for (int i = 1; i < size(); i++) lines.add(new Line(get(i - 1), get(i)));
double avgMinY = get(0).y;
SliceParameters P = new SliceParameters(5);
P.FL_REGRESS = false;
P.FL_BINS = 20;
// simple = 0.4
double A = 0.4;
// simple = 1;
double B = 1;
lines = new FindLines(lines, P) {
protected double nextAngle(Set<Line> remaining, int iteration) {
double delta = Math.PI / P.FL_BINS;
// angle bin
Bin<Line> aBin = new Bin(-Math.PI - delta, Math.PI + delta, P.FL_BINS * 2, true);
for (Line l : remaining) {
double len = l.length();
double angle = l.aTan2();
aBin.add(angle, len, l);
}
// return MUtils.PI2;
if (iteration < 1 && aBin.getWeight(Mathz.PI2) >= 5)
return Mathz.PI2;
int aBinI = aBin.maxI();
return aBin.val(aBinI);
}
protected double getTolNearLine(Point2d p) {
return P.FL_NEAR_LINE * (p.y < avgMinY + 5 ? 5 : B);
}
protected double getTolNearLine2(Point2d p) {
return P.FL_NEAR_LINE_2 * (p.y < avgMinY + 5 ? 10 : B);
}
}.result.all;
clean = new Prof(this);
clean.clear();
if (lines.isEmpty()) {
clean.add(new Point2d(0, 0));
clean.add(new Point2d(0, 1));
return clean;
}
List<Line> llines = new ArrayList(lines);
llines.stream().filter(l -> l.start.y > l.end.y).forEach(l -> l.reverseLocal());
Collections.sort(llines, new Comparator<Line>() {
public int compare(Line o1, Line o2) {
return Double.compare(o1.start.y + o1.end.y, o2.start.y + o2.end.y);
}
});
for (int i = 0; i < llines.size(); i++) {
Line l = llines.get(i);
double angle = l.aTan2();
if (angle < Mathz.PI2 + 0.1 && angle > Mathz.PI2 - 0.4)
llines.set(i, FindLines.rotateToAngle(l, l.fromPPram(0.5), Mathz.PI2));
}
Line bottomLine = llines.get(0);
llines.add(0, new Line(new Point2d(bottomLine.start.x, get(0).y), new Point2d(bottomLine.start.x, get(0).y)));
double lastY = -Double.MAX_VALUE, lastX = Double.MAX_VALUE;
for (Line l : llines) {
boolean startAbove = l.start.y >= lastY && l.start.x <= lastX, endAbove = l.end.y >= lastY && l.end.x <= lastX;
if (startAbove && endAbove) {
clean.add(l.start);
clean.add(l.end);
} else if (!startAbove && endAbove) {
if (l.start.y < lastY) {
Point2d sec = new LinearForm(new Vector2d(1, 0)).findC(new Point2d(0, lastY)).intersect(new LinearForm(l));
if (sec != null)
l.start = sec;
}
if (l.start.x > lastX) {
Point2d sec = new LinearForm(new Vector2d(0, 1)).findC(new Point2d(lastX, 0)).intersect(new LinearForm(l));
if (sec != null)
l.start = sec;
}
if (l.end.distanceSquared(l.start) < 100)
clean.add(l.start);
clean.add(l.end);
} else {
Vector2d dir = l.dir();
if (Math.abs(dir.x) > Math.abs(dir.y)) {
LinearForm x = new LinearForm(new Vector2d(1, 0)).findC(new Point2d(0, lastY));
l.start = x.project(l.start);
l.end = x.project(l.end);
l.start.x = Math.min(l.start.x, lastX);
l.end.x = Math.min(l.end.x, lastX);
} else {
LinearForm y = new LinearForm(new Vector2d(0, 1)).findC(new Point2d(lastX, 0));
l.start = y.project(l.start);
l.end = y.project(l.end);
l.start.y = Math.max(l.start.y, lastY);
l.end.y = Math.max(l.end.y, lastY);
}
clean.add(l.start);
clean.add(l.end);
}
lastY = l.end.y;
lastX = l.end.x;
}
clean.clean(0.2);
return clean;
}
Aggregations