public UVertex align(UVertex vv) { if (is2D) { return vv.rotZ(angle2D); } Vector3D v = toVector(vv); v = rot.applyInverseTo(v); return vv.set(v.getX(), v.getY(), v.getZ()); }
public UVertex[] getMidEdges() { UVertex[] mid = new UVertex[3]; getV(); mid[0] = UVertex.lerp(0.5f, v[0], v[1]); mid[1] = UVertex.lerp(0.5f, v[1], v[2]); mid[2] = UVertex.lerp(0.5f, v[2], v[0]); return mid; }
public UVertex normal() { if (normal != null) return normal; getV(); normal = UVertex.cross(v[2].copy().sub(v[0]), v[1].copy().sub(v[0])); // UVertex.delta(v[0],v[1]).norm() // UVertex.delta(v[0],v[2]).norm()); normal.norm(); return normal; }
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); }
// public static ArrayList<UHeading> getHeadings(UVertexList input,float headingDamper) { // ArrayList<UHeading> h=new ArrayList<UHeading>(); // UVertexList delta=input.deltaVectors(headingDamper); // if(rndBool()) delta=deltaVectors2(input); // for(UVertex hv:delta) h.add(new UHeading(hv)); // return h; // } // protected static UVertexList deltaVectors2(UVertexList input) { UVertexList dl = new UVertexList(); for (int i = 0; i < input.size(); i++) { UVertex tmp = null; if (i < input.size() - 1) { tmp = input.get(i + 1).copy().sub(input.get(i)); if (i > 0) tmp.add(input.get(i).copy().sub(input.get(i - 1))).mult(0.5f); } else tmp = input.get(i).copy().sub(input.get(i - 1)); dl.add(tmp); } return dl; }
/** * 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; }
public UVertex centroid() { if (centroid == null) { centroid = UVertex.centroid(getV()); } return centroid; }
public UFace set(UFace v) { vID = new int[v.vertexCount]; int cnt = 0; for (int i : v.vID) vID[cnt++] = i; col = v.col; parent = v.parent; if (v.normal != null) { if (normal != null) normal.set(v.normal.x, v.normal.y, v.normal.x); } return this; }
public static boolean check(UVertex v1, UVertex v2, UVertex v3) { if (v1.equals(v2) || v2.equals(v3) || v1.equals(v3)) return false; float d1 = v1.distSimple(v2); float d2 = v2.distSimple(v3); float d3 = v1.distSimple(v3); if (d1 < EPSILON || d2 < EPSILON || d3 < EPSILON) return false; return true; }
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; }
public void init() { if (main.nav == null) main.nav = new UNav3D(); UVertex v = new UVertex(1000, 0, 0); f = new UFace().set(v.copy(), v.copy().rotY(120 * DEG_TO_RAD), v.copy().rotY(240 * DEG_TO_RAD)); f.reverse(); UVertex.rotX(f.getV(), PI / 6); UVertex.rotZ(f.getV(), PI * 0.33f); UMB.log(f.getV()); f.rotX(f.rnd(TWO_PI)).rotZ(f.rnd(TWO_PI)); fv = UIntersections.faceYPlane(f, 0); lines = null; UMB.log(UMB.str(fv, ' ', null)); plane = UGeoGenerator.meshPlane(2000, 2000, 20).rotX(HALF_PI); }
private void drawLines() { for (int i = 0; i < inter.size(); i++) { ii = inter.get(i); a = lines.get(i * 2); b = lines.get(i * 2 + 1); if (ii != null) { UMB.pnoFill().pstroke(p.color(255, 255, 0)).pline(a, ii); UMB.pstroke(p.color(255, 0, 128)).pline(b, ii); p.text(ii.str(), ii.x, 20); UMB.ppush().ptranslate(ii); p.box(10); p.box(1); UMB.ppop(); UMB.ppush().ptranslate(b); p.box(5); UMB.ppop(); } else UMB.pstroke(0xffff0000).pline(a, b); } }
public boolean contains(UVertex vv) { getV(); for (UVertex vt : v) if (vt.equals(vv)) return true; return false; }
public UFace scale(float mx, float my, float mz) { for (UVertex vt : getV()) vt.mult(mx, my, mz); return reset(); }
public UFace rotZ(float deg) { for (UVertex vt : getV()) vt.rotZ(deg); return reset(); }
public UFace translate(float mx, float my, float mz) { for (UVertex vt : getV()) vt.add(mx, my, mz); return reset(); }