toxi.geom.Vec3D Java Examples
The following examples show how to use
toxi.geom.Vec3D.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Demo_Flocking3DAttractors.java From haxademic with MIT License | 6 votes |
public void update() { p.noStroke(); p.fill(255); findClosestAttractor(); // eases towards destination // position.interpolateTo(focus, 0.9f); vectorEase.x = P.lerp( vectorEase.x, target.x, speed ); vectorEase.y = P.lerp( vectorEase.y, target.y, speed ); vectorEase.z = P.lerp( vectorEase.z, target.z, speed ); vector = vectorEase.sub(position); position.addSelf(vector); Toxiclibs.instance(p).toxi.mesh( mesh.copy().pointTowards(target.sub(position), Vec3D.Z_AXIS).translate(position) ); }
Example #2
Source File: MidpointSubdiv.java From toxiclibs with GNU Lesser General Public License v2.1 | 6 votes |
public List<Vec3D[]> subdivideTriangle(Vec3D a, Vec3D b, Vec3D c, List<Vec3D[]> resultVertices) { Vec3D mab = a.interpolateTo(b, 0.5f); Vec3D mbc = b.interpolateTo(c, 0.5f); Vec3D mca = c.interpolateTo(a, 0.5f); resultVertices.add(new Vec3D[] { a, mab, mca }); resultVertices.add(new Vec3D[] { mab, b, mbc }); resultVertices.add(new Vec3D[] { mbc, c, mca }); resultVertices.add(new Vec3D[] { mab, mbc, mca }); return resultVertices; }
Example #3
Source File: ParticleString3D.java From toxiclibs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Creates a number of particles along a line and connects them into a * string using springs. * * @param physics * physics engine * @param pos * start position * @param step * step direction & distance between successive particles * @param num * number of particles * @param mass * particle mass * @param strength * spring strength */ public ParticleString3D(VerletPhysics3D physics, Vec3D pos, Vec3D step, int num, float mass, float strength) { this.physics = physics; particles = new ArrayList<VerletParticle3D>(num); links = new ArrayList<VerletSpring3D>(num - 1); float len = step.magnitude(); VerletParticle3D prev = null; pos = pos.copy(); for (int i = 0; i < num; i++) { VerletParticle3D p = new VerletParticle3D(pos.copy(), mass); particles.add(p); physics.particles.add(p); if (prev != null) { VerletSpring3D s = createSpring(prev, p, len, strength); links.add(s); physics.addSpring(s); } prev = p; pos.addSelf(step); } }
Example #4
Source File: FlockingBoidsShiffmanToxi.java From haxademic with MIT License | 6 votes |
Vec3D cohesion (ArrayList boids) { Vec3D sum = new Vec3D(); // Start with empty vector to accumulate all locations int count = 0; for (int i = boids.size()-1 ; i >= 0 ; i--) { Boid other = (Boid) boids.get(i); if (this != other) { if (loc.distanceToSquared(other.loc) < neighborDist) { sum.addSelf(other.loc); // Add location count++; } } } if (count > 0) { sum.scaleSelf(1.0f/count); return steer(sum,false); // Steer towards the location } return sum; }
Example #5
Source File: VectorFlyerToxi.java From haxademic with MIT License | 6 votes |
public VectorFlyerToxi( TColor colorLow, TColor colorHigh ) { DebugUtil.printErr("This VectorFlyer class should be deprecated"); p = (PAppletHax) P.p; accel = p.random(0.5f, 8.0f); maxSpeed = p.random(5f, 45f); color = new EasingColor( colorLow.red(), colorLow.green(), colorLow.blue() ); float size = p.random(10f,35f); // ZAxisCylinder cylinder = new ZAxisCylinder(new Vec3D(), size/8, size ); // mesh = (TriangleMesh)cylinder.toMesh(); mesh = (TriangleMesh)(new AABB(size)).toMesh(); mesh.scale(new Vec3D(0.25f, 0.25f, 1)); // mesh = MeshUtil.meshFromOBJ( p, FileUtil.getHaxademicDataPath() + "models/pointer_cursor_2_hollow.obj", 0.005f * size ); // mesh.rotateX(P.PI/2f); }
Example #6
Source File: NurbsCreator.java From toxiclibs with GNU Lesser General Public License v2.1 | 6 votes |
private static void lineIntersect3D(Vec3D p0, Vec3D t0, Vec3D p2, Vec3D t2, Vec3D out0, Vec3D out2) { Vec3D v02 = p0.sub(p2); double a = t0.dot(t0); double b = t0.dot(t2); double c = t2.dot(t2); double d = t0.dot(v02); double e = t2.dot(v02); double denom = a * c - b * b; double mu0, mu2; if (denom < MathUtils.EPS) { mu0 = 0; mu2 = b > c ? d / b : e / c; } else { mu0 = (b * e - c * d) / denom; mu2 = (a * e - b * d) / denom; } out0.set(t0.scale((float) mu0).addSelf(p0)); out2.set(t2.scale((float) mu2).addSelf(p2)); }
Example #7
Source File: TiledFrameExporter.java From toxiclibs with GNU Lesser General Public License v2.1 | 6 votes |
TiledFrameExporter(PApplet p, int n) { parent = p; numTiles = n; buffer = new PImage(p.width * n, p.height * n); offsets = new Vec3D[numTiles * numTiles]; normTileSize = 2.0 / numTiles; aspect = (double) p.height / p.width; int idx = 0; double y = 1 - normTileSize; while (idx < offsets.length) { double x = -1; for (int xi = 0; xi < numTiles; xi++) { offsets[idx++] = new Vec3D((float) x, (float) y, 0); x += normTileSize; } y -= normTileSize; } }
Example #8
Source File: Origin3DTest.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public void testViewConstruct() { Origin3D o = new Origin3D(new Vec3D(0, -100, 0), new Vec3D(0, 1, 0)); System.out.println(o.xAxis); System.out.println(o.yAxis); System.out.println(o.zAxis); System.out.println(o.xAxis.angleBetween(o.zAxis)); }
Example #9
Source File: WETriangleMesh.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public WETriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c, Vec3D n, Vec2D uvA, Vec2D uvB, Vec2D uvC) { WEVertex va = checkVertex(a); WEVertex vb = checkVertex(b); WEVertex vc = checkVertex(c); if (va.id == vb.id || va.id == vc.id || vb.id == vc.id) { if (logger.isLoggable(Level.FINE)) { logger.fine("ignorning invalid face: " + a + "," + b + "," + c); } } else { if (n != null) { Vec3D nc = va.sub(vc).crossSelf(va.sub(vb)); if (n.dot(nc) < 0) { WEVertex t = va; va = vb; vb = t; } } WEFace f = new WEFace(va, vb, vc, uvA, uvB, uvC); faces.add(f); numFaces++; updateEdge(va, vb, f); updateEdge(vb, vc, f); updateEdge(vc, va, f); } return this; }
Example #10
Source File: ToxiclibsSupport.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public final void triangle(Triangle3D tri, boolean isFullShape) { if (isFullShape) { gfx.beginShape(PConstants.TRIANGLES); } Vec3D n = tri.computeNormal(); gfx.normal(n.x, n.y, n.z); gfx.vertex(tri.a.x, tri.a.y, tri.a.z); gfx.vertex(tri.b.x, tri.b.y, tri.b.z); gfx.vertex(tri.c.x, tri.c.y, tri.c.z); if (isFullShape) { gfx.endShape(); } }
Example #11
Source File: Compute3D.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void execute(Vec3D p, PixelOffset px) { if (depthData.planeAndProjectionCalibration.hasGoodOrientation(p)) { // Vec3D projected = depthData.planeAndProjectionCalibration.project(p); // depthData.projectedPoints[px.offset] = projected; depthData.planeAndProjectionCalibration.project(p, depthData.projectedPoints[px.offset]); selection.validPointsMask[px.offset] = true; selection.validPointsList.add(px.offset); } }
Example #12
Source File: TriangleMeshTest.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); mesh = new TriangleMesh("foo"); mesh.addFace(new Vec3D(), new Vec3D(100, 100, 0), new Vec3D(100, 0, 0)); mesh.addFace(new Vec3D(100, 100, 0), new Vec3D(100, 0, -100), new Vec3D(100, 0, 0)); mesh.addFace(new Vec3D(100f, 0, -100), new Vec3D(0, 100, -100), new Vec3D(0, 0, -100)); }
Example #13
Source File: Compute3D.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void execute(Vec3D p, PixelOffset px) { if (depthData.planeAndProjectionCalibration.hasGoodOrientation(p)) { // Vec3D projected = depthData.planeAndProjectionCalibration.project(p); // depthData.projectedPoints[px.offset] = projected; depthData.planeAndProjectionCalibration.project(p, depthData.projectedPoints[px.offset]); if (isInside(depthData.projectedPoints[px.offset], 0.f, 1.f, 0.1f)) { selection.validPointsMask[px.offset] = true; selection.validPointsList.add(px.offset); } } }
Example #14
Source File: TriangleTest.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public void testContainment() { Vec3D a = new Vec3D(100, 0, 0); Vec3D b = new Vec3D(0, 100, 0); Vec3D c = new Vec3D(0, 0, 100); Triangle3D t = new Triangle3D(a, b, c); assertTrue(t.containsPoint(a)); assertTrue(t.containsPoint(b)); assertTrue(t.containsPoint(c)); assertTrue(t.containsPoint(t.computeCentroid())); assertFalse(t.containsPoint(a.add(0.1f, 0, 0))); t.flipVertexOrder(); assertTrue(t.containsPoint(t.computeCentroid())); }
Example #15
Source File: DLA.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
protected void alignAttachedParticle(DLAParticle p, Vec3D target) { Vec3D d = p.sub(target).normalize(); d.interpolateToSelf(dirCurvePoint, config.getCurveAlign()); d.scaleSelf(config.getGrowthScale()); d.normalizeTo(config.getParticleRadius()); p.set(target).addSelf(d); }
Example #16
Source File: PhysTest.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public void setup() { size(1024, 768, P3D); smooth(); physics = new VerletPhysics3D(); // physics.addBehavior(new GravityBehavior(new Vec3D(0, 0.2f, 0), // 0.6f)); Vec3D stepDir = new Vec3D(1, 0, 0).normalizeTo(REST_LENGTH); ParticleString3D s = new ParticleString3D(physics, new Vec3D(), stepDir, NUM_PARTICLES, 1, 0.1f); head = s.getHead(); head.lock(); tail = s.getTail(); physics.addBehavior(new AttractionBehavior3D(new Vec3D(), 400, 0.5f)); }
Example #17
Source File: ConnectedComponent.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
public float getHeight(Vec3D[] array) { float min = Float.MAX_VALUE; float max = 0; for (int offset : this) { float z = array[offset].z; if (z < min) { min = z; } if (z > max) { max = z; } } return max - min; }
Example #18
Source File: FlockingBoidsShiffmanToxi.java From haxademic with MIT License | 5 votes |
protected void firstFrame() { flock = new Flock(); // Add an initial set of boids into the system for (int i = 0; i < NUM; i++) { flock.addBoid(new Boid(new Vec3D(), 3, 0.05f, NEIGHBOR_DIST, SEPARATION)); } smooth(); }
Example #19
Source File: DLAGuideLines.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public DLAGuideLines addLine(Vec3D a, Vec3D b) { DLASegment s = new DLASegment(a, b, null); if (logger.isLoggable(Level.INFO)) { logger.info("adding line segment: " + s); } segments.add(s); return this; }
Example #20
Source File: ExtrinsicCalibrator.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
private PlaneCalibration computeAveragePlaneKinect(ArrayList<ExtrinsicSnapshot> snapshots, PMatrix3D stereoExtr) { PVector paperSize = new PVector(297, 210); Plane sumKinect = new Plane(new Vec3D(0, 0, 0), new Vec3D(0, 0, 0)); int nbCalib = 0; for (ExtrinsicSnapshot snapshot : snapshots) { if (snapshot.kinectPaper == null) { continue; } // color -> paper PMatrix3D boardFromDepth = snapshot.kinectPaper.get(); // Depth -> color -> color -> paper boardFromDepth.preApply(stereoExtr); PlaneCalibration planeCalibKinect = PlaneCalibration.CreatePlaneCalibrationFrom(boardFromDepth, paperSize); Utils.sumPlane(sumKinect, planeCalibKinect.getPlane()); nbCalib++; } Utils.averagePlane(sumKinect, 1f / nbCalib); PlaneCalibration calibration = new PlaneCalibration(); calibration.setPlane(sumKinect); calibration.setHeight(PlaneCalibration.DEFAULT_PLANE_HEIGHT); // System.out.println("Plane viewed by the kinect"); // println(sumKinect); return calibration; }
Example #21
Source File: Vec3DTest.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public void testClosestAxis() { assertEquals(Vec3D.Axis.X, new Vec3D(-1, 0.9f, 0.8f).getClosestAxis()); assertEquals(null, new Vec3D(1, -1, 0).getClosestAxis()); assertEquals(null, new Vec3D(1, 0, -1).getClosestAxis()); assertEquals(Vec3D.Axis.Y, new Vec3D(0.8f, -1, -0.99999f).getClosestAxis()); assertEquals(null, new Vec3D(0.8f, -1, 1).getClosestAxis()); assertEquals(Vec3D.Axis.Z, new Vec3D(0.8f, -1, 1.1f).getClosestAxis()); assertEquals(Vec3D.Axis.X, new Vec3D(1, 0, 0).getClosestAxis()); assertEquals(Vec3D.Axis.Y, new Vec3D(0, -1, 0).getClosestAxis()); assertEquals(Vec3D.Axis.Z, new Vec3D(0, 0, 1).getClosestAxis()); }
Example #22
Source File: ToxiclibsSupport.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public final void processVertices3D(Iterator<? extends Vec3D> iterator, int shapeID, boolean closed, float scale) { gfx.beginShape(shapeID); while (iterator.hasNext()) { Vec3D v = iterator.next(); gfx.vertex(v.x * scale, v.y * scale, v.z * scale); } if (closed) { gfx.endShape(PConstants.CLOSE); } else { gfx.endShape(); } }
Example #23
Source File: DLA.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
protected void parseGuidelines() { guidelines.reset(); octreeGuides.empty(); while (!guidelines.isComplete()) { double density = config.getGuideLineDensity(); guidelines.updatePoint(density); Vec3D p = guidelines.getPoint(); octreeGuides.addPoint(p); } guidelines.reset(); }
Example #24
Source File: IndexedTriangleMesh.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public IndexedTriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c, HashMap<String, Object[]> attribs) { int idA = vertices.index(a); int idB = vertices.index(b); int idC = vertices.index(c); if (idA != idB && idA != idC && idB != idC) { AttributedFace f = new AttributedFace(idA, idB, idC, addFaceAttributes(null, attribs)); faces.add(f); } return this; }
Example #25
Source File: TriSubdivision.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public List<Vec3D> computeSplitPoints(WingedEdge edge) { List<Vec3D> mid = new ArrayList<Vec3D>(3); mid.add(edge.a.interpolateTo(edge.b, 0.25f)); mid.add(edge.a.interpolateTo(edge.b, 0.5f)); mid.add(edge.a.interpolateTo(edge.b, 0.75f)); return mid; }
Example #26
Source File: TriangleMesh.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public TriangleMesh faceOutwards() { computeCentroid(); for (Face f : faces) { Vec3D n = f.getCentroid().sub(centroid); float dot = n.dot(f.normal); if (dot < 0) { f.flipVertexOrder(); } } return this; }
Example #27
Source File: TriangleTest.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public void testCentroid() { Vec3D a = new Vec3D(100, 0, 0); Vec3D b = new Vec3D(0, 100, 0); Vec3D c = new Vec3D(0, 0, 100); Triangle3D t = new Triangle3D(a, b, c); ReadonlyVec3D centroid = t.computeCentroid(); assertTrue("incorrect centroid", centroid.equals(new Vec3D(100, 100, 100).scaleSelf(1f / 3))); }
Example #28
Source File: WEMeshTest.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void setUp() throws Exception { m = new WETriangleMesh("plane", 4, 2); m.addFace(new Vec3D(), new Vec3D(100, 0, 0), new Vec3D(100, 100, 0)); m.addFace(new Vec3D(), new Vec3D(100, 100, 0), new Vec3D(0, 100, 0)); super.setUp(); }
Example #29
Source File: PointMeshToVec.java From haxademic with MIT License | 5 votes |
public void updateBoxes() { p.noStroke(); p.fill(255); position.addSelf(vector); box.set(position); TriangleMesh meshhh = (TriangleMesh)box.toMesh(); Toxiclibs.instance(p).toxi.mesh( meshhh.copy().pointTowards(focus.sub(position), Vec3D.Z_AXIS).translate(position) ); p.fill(255, 0, 0); p.stroke(255, 0, 0); Toxiclibs.instance(p).toxi.mesh( focus.toMesh() ); Toxiclibs.instance(p).toxi.line(position, focus); }
Example #30
Source File: STLWriter.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public void face(Vec3D a, Vec3D b, Vec3D c, int rgb) { Vec3D normal = b.sub(a).crossSelf(c.sub(a)).normalize(); if (useInvertedNormals) { normal.invert(); } face(a, b, c, normal, rgb); }