void setupParticleSystem(Autodesk.Revit.DB.Face f, int uDiv, int vDiv, double springDampening, double springRestLength, double springConstant, double mass) { BoundingBoxUV bbox = f.GetBoundingBox(); double uStep = (bbox.Max.U - bbox.Min.U) / uDiv; double vStep = (bbox.Max.V - bbox.Min.V) / vDiv; for (int j = 0; j <= uDiv; j++) // Y axis is outer loop { double u = bbox.Min.U + uStep * j; for (int i = 0; i <= vDiv; i++) // X axis is inner loop { double v = bbox.Min.V + vStep * i; Particle a = ParticleSystem.makeParticle(mass, f.Evaluate(new UV(u, v)), false); if (i > 0) { ParticleSystem.makeSpring(ParticleSystem.getParticle((i - 1) + (j * (vDiv + 1))), a, springRestLength, springConstant, springDampening); } if (j > 0) { Particle b = ParticleSystem.getParticle(i + ((j - 1) * (vDiv + 1))); ParticleSystem.makeSpring(a, b, springRestLength, springConstant, springDampening); } if (i == 0 || i == vDiv || j == 0 || j == uDiv) { a.makeFixed(); } } } }
void CreateChainWithTwoFixedEnds(ReferencePoint pt1, ReferencePoint pt2, int numX, double springDampening, double springRestLength, double springConstant, double mass) { Particle p; Particle p2; XYZ partXYZ1 = pt1.Position; XYZ partXYZ2 = pt2.Position; XYZ lineVec = partXYZ2 - partXYZ1; double stepSize = lineVec.GetLength() / numX; for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts { //double curveParam = 0; XYZ pointOnLine; if (j == 0) // starting point { p = ParticleSystem.makeParticle(mass, partXYZ1, true); // make first particle fixed } else if (j > 0 && j < numX - 1) // middle points { pointOnLine = partXYZ1 + lineVec.Normalize() * (j * stepSize); p = ParticleSystem.makeParticle(mass, pointOnLine, false); // make a new particle along curve at j-th point on line p2 = ParticleSystem.getParticle(j - 1); ParticleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening); //make a new spring and connect it to the last-made point } else //last point - fixed { p = ParticleSystem.getParticle(j - 1); p2 = ParticleSystem.makeParticle(mass, partXYZ2, true); // make last particle fixed ParticleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening); //make a new spring and connect the j-th point to the fixed point } } }
void CreateChainWithOneFixedEnd(ReferencePoint pt1, int numX, double springDampening, double springRestLength, double springConstant, double mass) { Particle p; XYZ partXYZ1 = pt1.Position; Particle fixedPart1 = ParticleSystem.makeParticleFromElementID(pt1.Id, mass, pt1.Position, true); // true means 'make fixed' XYZ partXYZ2 = partXYZ1 + new XYZ(10, 0, 0); //Line tempLine = this.UIDocument.Application.Application.Create.NewLineBound(partXYZ1, partXYZ2); XYZ vector = partXYZ2 - partXYZ1; XYZ step = vector.Divide(numX); for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts { //double curveParam = 0; XYZ pointOnLine; pointOnLine = partXYZ1 + step.Multiply(j); if (j == 0) // starting point { //curveParam = (double)j / numX; //pointOnLine = tempLine.Evaluate(curveParam, true); p = ParticleSystem.makeParticle(mass, pointOnLine, true); // make first particle fixed } else // middle points { //curveParam = (double)j / numX; //pointOnLine = tempLine.Evaluate(curveParam, true); p = ParticleSystem.makeParticle(mass, pointOnLine, false); // make a new particle along curve at j-th point on line ParticleSystem.makeSpring(ParticleSystem.getParticle((j - 1)), p, springRestLength, springConstant, springDampening); //make a new spring and connect it to the last-made point } } }
public void Draw() { if (this.RenderDescription == null) { this.RenderDescription = new Nodes.RenderDescription(); } if (particleSystem == null) { return; } for (int i = 0; i < particleSystem.numberOfParticles(); i++) { Particle p = particleSystem.getParticle(i); XYZ pos = p.getPosition(); if (i < this.RenderDescription.points.Count()) { this.RenderDescription.points[i] = new Point3D(pos.X, pos.Y, pos.Z); } else { Point3D pt = new System.Windows.Media.Media3D.Point3D(pos.X, pos.Y, pos.Z); this.RenderDescription.points.Add(pt); } } for (int i = 0; i < particleSystem.numberOfSprings(); i++) { ParticleSpring ps = particleSystem.getSpring(i); XYZ pos1 = ps.getOneEnd().getPosition(); XYZ pos2 = ps.getTheOtherEnd().getPosition(); if (i * 2 + 1 < this.RenderDescription.lines.Count()) { this.RenderDescription.lines[i * 2] = new Point3D(pos1.X, pos1.Y, pos1.Z); this.RenderDescription.lines[i * 2 + 1] = new Point3D(pos2.X, pos2.Y, pos2.Z); } else { Point3D pt1 = new System.Windows.Media.Media3D.Point3D(pos1.X, pos1.Y, pos1.Z); Point3D pt2 = new System.Windows.Media.Media3D.Point3D(pos2.X, pos2.Y, pos2.Z); this.RenderDescription.lines.Add(pt1); this.RenderDescription.lines.Add(pt2); } } }
public void Draw() { if (RenderDescription == null) { RenderDescription = new RenderDescription(); } if (ParticleSystem == null) { return; } for (int i = 0; i < ParticleSystem.numberOfParticles(); i++) { Particle p = ParticleSystem.getParticle(i); XYZ pos = p.getPosition(); if (i < RenderDescription.points.Count()) { RenderDescription.points[i] = new Point3D(pos.X, pos.Y, pos.Z); } else { var pt = new Point3D(pos.X, pos.Y, pos.Z); RenderDescription.points.Add(pt); } } for (int i = 0; i < ParticleSystem.numberOfSprings(); i++) { ParticleSpring ps = ParticleSystem.getSpring(i); XYZ pos1 = ps.getOneEnd().getPosition(); XYZ pos2 = ps.getTheOtherEnd().getPosition(); if (i * 2 + 1 < RenderDescription.lines.Count()) { RenderDescription.lines[i * 2] = new Point3D(pos1.X, pos1.Y, pos1.Z); RenderDescription.lines[i * 2 + 1] = new Point3D(pos2.X, pos2.Y, pos2.Z); } else { var pt1 = new Point3D(pos1.X, pos1.Y, pos1.Z); var pt2 = new Point3D(pos2.X, pos2.Y, pos2.Z); RenderDescription.lines.Add(pt1); RenderDescription.lines.Add(pt2); } } }
public override Value Evaluate(FSharpList <Value> args) { ParticleSystem particleSystem = (ParticleSystem)((Value.Container)args[0]).Item; var result = FSharpList <Value> .Empty; Particle p; XYZ pt; //create an XYZ from each Particle for (int i = 0; i < particleSystem.numberOfParticles(); i++) { p = particleSystem.getParticle(i); pt = new XYZ(p.getPosition().X, p.getPosition().Y, p.getPosition().Z); result = FSharpList <Value> .Cons(Value.NewContainer(pt), result); } return(Value.NewList(result)); }
private void UpdateSystem() { //update the spring values for (int j = 0; j < ParticleSystem.numberOfSprings(); j++) { ParticleSpring spring = ParticleSystem.getSpring(j); spring.setDamping(_d); if (!_useRl) { spring.setRestLength(_r); } spring.setSpringConstant(_s); } for (int j = 0; j < ParticleSystem.numberOfParticles(); j++) { Particle p = ParticleSystem.getParticle(j); p.setMass(_m); } }
void setupLineTest(int maxPartX, int maxPartY, double springDampening, double springRestLength, double springConstant, double mass) { XYZ partXYZ; double stepSize = 20; for (int j = 0; j < maxPartY; j++) // Y axis is outer loop { for (int i = 0; i < maxPartX; i++) // X axis is inner loop { if (i == 0) { partXYZ = new XYZ(0, j * stepSize, 0); Particle a = ParticleSystem.makeParticle(mass, partXYZ, true); } else { partXYZ = new XYZ(i * stepSize, j * stepSize, 0); Particle b = ParticleSystem.makeParticle(mass, partXYZ, false); ParticleSystem.makeSpring(ParticleSystem.getParticle((i - 1) + (j * maxPartX)), b, springRestLength, springConstant, springDampening); } if (i == maxPartX - 1) { ParticleSystem.getParticle(i + (j * maxPartX)).makeFixed(); } } if (j > 0) // thread multple chains together along Y axis { for (int i = 0; i < maxPartX; i++) { Particle a = ParticleSystem.getParticle(i + (j * maxPartX)); Particle b = ParticleSystem.getParticle(i + ((j - 1) * maxPartX)); ParticleSystem.makeSpring(a, b, springRestLength, springConstant, springDampening); } } } }
public void step(double t) { s.clearForces(); s.applyForces(); double halftt = 0.5 * t * t; double tt = t * t; for (int i = 0; i < s.numberOfParticles(); i++) { Particle p = s.getParticle(i); if (p.isFree()) { XYZ a = p.getForce() / p.getMass(); XYZ xmm = p.getOldPosition(); XYZ xm = p.getPosition(); XYZ x = xm.Add(xm - xmm) + a * tt; XYZ vm = p.getVelocity(); p.setPosition(x); p.setVelocity((x - xmm) / (2 * t)); } } }