protected static UVertexList deltaVectors3(UVertexList input) { UVertexList dl = new UVertexList(); boolean isClosed = input.isClosed(); for (int i = 0; i < input.size(); i++) { UVertex vv = null, vn = null, vp = null; vv = input.get(i); if (i > 0) vp = input.get(i - 1); if (i == 0 && isClosed) vp = input.last(); if (i < input.size() - 1) vn = input.get(i + 1); else if (isClosed) vn = input.first(); if (vn != null) vn = vn.copy().sub(vv); // .norm(); if (vp != null) vp = vv.copy().sub(vp); // .norm(); if (vp != null && vn != null) vv = vn.add(vp).mult(0.5f); else if (vn == null) vv = vp; else vv = vn; log( i + "/" + input.size() + " " + isClosed + " vp=" + (vp != null) + " vn=" + (vn != null) + " " + vv.str()); dl.add(vv); // if(i<input.size()-1) { // tmp=input.get(i+1).copy().sub(input.get(i)).norm(); // if(i>0) tmp.add( // input.get(i).copy().sub(input.get(i-1)).norm()).mult(0.5f); // } // else tmp=input.get(i).copy().sub(input.get(i-1)); // dl.add(tmp); } return dl; }
private void initHeading(UVertex thedir) { this.dir = thedir.copy().norm(); if (is2D) { angle2D = dir.angleXY(); return; } Vector3D v = toVector(dir); // System.out.println(v.getX()+" "+v.getY()+" "+v.getZ()); rot = new Rotation(v, new Vector3D(0, 0, 1)); // -UConst.HALF_PI); // rot=new Rotation(order,dir.x,dir.y,dir.z); }
/** * Aligns and scales a UGeo instance so that the result geometry lies along the vector given by * the input vertices. <code>geo</code> is assumed to be facing "forward" along the positive Z * axis and will be scaled along that axis to match the length of the input vector, leaving the X * and Y dimensions unchanged. * * @param geo * @param v1 * @param v2 * @return */ public static UGeo align(UGeo geo, UVertex v1, UVertex v2, float extend) { UVertex dir = v2.copy().sub(v1); UHeading h = new UHeading(dir); // UMB.log(dir.mag()+" "+geo.dimZ()); float m = dir.mag(); if (extend > 0) m += extend * 2; geo.center().scale(1, 1, m / geo.dimZ()); h.align(geo.getV()); geo.translate(dir.mult(0.5f).add(v1)); return geo; }