Java Code Examples for toxi.geom.Vec3D#scaleSelf()
The following examples show how to use
toxi.geom.Vec3D#scaleSelf() .
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: TouchDetectionColor.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
protected TrackedElement createTouchPoint(ConnectedComponent connectedComponent, float scale) { Vec3D meanProj = connectedComponent.getMean(imgSize); TrackedElement tp = new TrackedElement(); tp.setDetection(this); meanProj.scaleSelf(1f / scale); tp.setPosition(meanProj); tp.setCreationTime(this.currentTime); tp.setConfidence(connectedComponent.size()); // We attach the colorID here. tp.attachedValue = segmentedImage[connectedComponent.get(0)]; // TODO: re-enable this one day ? // tp.setConnectedComponent(connectedComponent); // EXPERIMENTAL, check if a copy is necessary // tp.setSource(connectedComponent); return tp; }
Example 2
Source File: FlockingBoidsShiffmanToxi.java From haxademic with MIT License | 6 votes |
Vec3D align (ArrayList boids) { Vec3D steer = new Vec3D(); 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) { steer.addSelf(other.vel); count++; } } } if (count > 0) { steer.scaleSelf(1.0f/count); } // As long as the vector is greater than 0 if (steer.magSquared() > 0) { // Implement Reynolds: Steering = Desired - Velocity steer.normalizeTo(maxspeed); steer.subSelf(vel); steer.limit(maxforce); } return steer; }
Example 3
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 4
Source File: ConnectedComponent.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
/** * Find the mean location if offset positions. * @param size * @return */ public Vec3D getMean(WithSize size) { Vec3D mean = new Vec3D(0, 0, 0); for (int offset : this) { int x = offset % size.getWidth(); int y = (int) offset / size.getWidth(); mean.addSelf(x, y, 0); } mean.scaleSelf(1.0f / this.size()); return mean; }
Example 5
Source File: ConnectedComponent.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get the mean location given an input array of positions. * @param array * @return */ public Vec3D getMean(Vec3D[] array) { Vec3D mean = new Vec3D(0, 0, 0); for (int offset : this) { mean.addSelf(array[offset]); } mean.scaleSelf(1.0f / this.size()); return mean; }
Example 6
Source File: IndexedTriangleMesh.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
public IndexedTriangleMesh smooth() { HashMap<Integer, Vec3D> lapIndex = new HashMap<Integer, Vec3D>(); List<Vec3D> neighbors = null; for (int i = 0, numV = getNumVertices(); i < numV; i++) { neighbors = getNeighborsForVertexID(i, neighbors); if (neighbors != null && neighbors.size() > 0) { Vec3D l = new Vec3D(); for (Vec3D n : neighbors) { l.addSelf(n); } l.scaleSelf(1f / neighbors.size()); lapIndex.put(i, l); } } SpatialIndex newVerts = new SpatialIndex(vertices.getDelta()); for (Iterator<AttributedFace> i = faces.iterator(); i.hasNext();) { AttributedFace f = i.next(); f.a = newVerts.index(lapIndex.get(f.a)); f.b = newVerts.index(lapIndex.get(f.b)); f.c = newVerts.index(lapIndex.get(f.c)); if (f.a == f.b || f.a == f.c || f.b == f.c) { i.remove(); } } vertices = newVerts; computeEdges(); return this; }
Example 7
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 8
Source File: FlockingBoidsShiffmanToxi.java From haxademic with MIT License | 5 votes |
void flock(ArrayList boids) { Vec3D sep = separate(boids); // Separation Vec3D ali = align(boids); // Alignment Vec3D coh = cohesion(boids); // Cohesion // Arbitrarily weight these forces sep.scaleSelf(1.5f); ali.scaleSelf(1.0f); coh.scaleSelf(1.0f); // Add the force vectors to acceleration acc.addSelf(sep); acc.addSelf(ali); acc.addSelf(coh); }
Example 9
Source File: FlockingBoidsShiffmanToxi.java From haxademic with MIT License | 5 votes |
Vec3D separate (ArrayList boids) { Vec3D steer = new Vec3D(); int count = 0; // For every boid in the system, check if it's too close for (int i = boids.size()-1 ; i >= 0 ; i--) { Boid other = (Boid) boids.get(i); if (this != other) { float d = loc.distanceTo(other.loc); // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself) if (d < desiredSeparation) { // Calculate vector pointing away from neighbor Vec3D diff = loc.sub(other.loc); diff.normalizeTo(1.0f/d); steer.addSelf(diff); count++; } } } // Average -- divide by how many if (count > 0) { steer.scaleSelf(1.0f/count); } // As long as the vector is greater than 0 if (steer.magSquared() > 0) { // Implement Reynolds: Steering = Desired - Velocity steer.normalizeTo(maxspeed); steer.subSelf(vel); steer.limit(maxforce); } return steer; }