Пример #1
0
        /// <summary>
        /// Satisfies the constraint.
        /// </summary>
        /// <param name="vs">
        /// The verlet system.
        /// </param>
        /// <param name="iteration">
        /// The iteration.
        /// </param>
        public override void Satisfy(VerletIntegrator vs, int iteration)
        {
            if (this.Iterations > iteration)
            {
                Point3D  x1    = vs.Positions[this.Index1];
                Point3D  x2    = vs.Positions[this.Index2];
                Vector3D delta = x2 - x1;

                double deltalength = delta.Length;
                double diff        = deltalength - this.Restlength;

                double div = deltalength * (vs.InverseMass[this.Index1] + vs.InverseMass[this.Index2]);

                if (Math.Abs(div) > 1e-8)
                {
                    diff /= div;
                    if (vs.InverseMass[this.Index1] != 0)
                    {
                        vs.Positions[this.Index1] += delta * diff * vs.InverseMass[this.Index1] * this.RelaxationFactor;
                    }

                    if (vs.InverseMass[this.Index2] != 0)
                    {
                        vs.Positions[this.Index2] -= delta * diff * vs.InverseMass[this.Index2] * this.RelaxationFactor;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Satisfies the constraint.
        /// </summary>
        /// <param name="vs">
        /// The verlet system.
        /// </param>
        /// <param name="iteration">
        /// The iteration.
        /// </param>
        public override void Satisfy(VerletIntegrator vs, int iteration)
        {
            Vector3D vec = Point3D.Subtract(vs.Positions[this.Index], this.Center);

            if (vec.LengthSquared < this.RadiusSquared)
            {
                vec.Normalize();
                vs.Positions[this.Index]  = this.Center + vec * this.Radius * 1.1;
                vs.Positions0[this.Index] = vs.Positions[this.Index];
            }
        }
Пример #3
0
        /// <summary>
        /// Satisfies the constraint.
        /// </summary>
        /// <param name="vs">
        /// The verlet system.
        /// </param>
        /// <param name="iteration">
        /// The iteration.
        /// </param>
        public override void Satisfy(VerletIntegrator vs, int iteration)
        {
            int     i = this.Index;
            Point3D x = vs.Positions[i];

            if (x.Z <= 0)
            {
                if (this.Friction != 0)
                {
                    double   f = -x.Z * this.Friction;
                    Vector3D v = vs.Positions[i] - vs.Positions0[i];
                    v.Z = 0;

                    if (v.X > 0)
                    {
                        v.X -= f * v.X;
                        if (v.X < 0)
                        {
                            v.X = 0;
                        }
                    }
                    else
                    {
                        v.X += f;
                        if (v.X > 0)
                        {
                            v.X = 0;
                        }
                    }

                    if (v.Y > 0)
                    {
                        v.Y -= f * v.Y;
                        if (v.Y < 0)
                        {
                            v.Y = 0;
                        }
                    }
                    else
                    {
                        v.Y += f;
                        if (v.Y > 0)
                        {
                            v.Y = 0;
                        }
                    }

                    vs.Positions0[i] = vs.Positions[i] - v;
                }

                vs.Positions[i].Z = 0;
            }
        }
Пример #4
0
 public Flag(string image)
 {
     Mesh = new MeshGeometry3D();
     Material = MaterialHelper.CreateImageMaterial(image);
     Damping = 0.98;
     integrator = new VerletIntegrator() { Iterations = 4, Damping = this.Damping };
     WindSpeed = 6;
     WindDirection = 180;
     PoleHeight = 12;
     Height = 3;
     Length = 4;
     Mass = 0.8;
 }
Пример #5
0
 /// <summary>
 /// Satisfies the constraint.
 /// </summary>
 /// <param name="vs">
 /// The verlet system.
 /// </param>
 /// <param name="iteration">
 /// The iteration.
 /// </param>
 public abstract void Satisfy(VerletIntegrator vs, int iteration);
Пример #6
0
 /// <summary>
 /// Satisfies the constraint.
 /// </summary>
 /// <param name="vs">
 /// The verlet system.
 /// </param>
 /// <param name="iteration">
 /// The iteration.
 /// </param>
 public override void Satisfy(VerletIntegrator vs, int iteration)
 {
     Vector3D vec = Point3D.Subtract(vs.Positions[this.Index], this.Center);
     if (vec.LengthSquared < this.RadiusSquared)
     {
         vec.Normalize();
         vs.Positions[this.Index] = this.Center + vec * this.Radius * 1.1;
         vs.Positions0[this.Index] = vs.Positions[this.Index];
     }
 }
Пример #7
0
 /// <summary>
 /// Satisfies the constraint.
 /// </summary>
 /// <param name="vs">
 /// The verlet system.
 /// </param>
 /// <param name="iteration">
 /// The iteration.
 /// </param>
 public abstract void Satisfy(VerletIntegrator vs, int iteration);
Пример #8
0
        /// <summary>
        /// Satisfies the constraint.
        /// </summary>
        /// <param name="vs">
        /// The verlet system.
        /// </param>
        /// <param name="iteration">
        /// The iteration.
        /// </param>
        public override void Satisfy(VerletIntegrator vs, int iteration)
        {
            int i = this.Index;
            Point3D x = vs.Positions[i];
            if (x.Z <= 0)
            {
                if (this.Friction != 0)
                {
                    double f = -x.Z * this.Friction;
                    Vector3D v = vs.Positions[i] - vs.Positions0[i];
                    v.Z = 0;

                    if (v.X > 0)
                    {
                        v.X -= f * v.X;
                        if (v.X < 0)
                        {
                            v.X = 0;
                        }
                    }
                    else
                    {
                        v.X += f;
                        if (v.X > 0)
                        {
                            v.X = 0;
                        }
                    }

                    if (v.Y > 0)
                    {
                        v.Y -= f * v.Y;
                        if (v.Y < 0)
                        {
                            v.Y = 0;
                        }
                    }
                    else
                    {
                        v.Y += f;
                        if (v.Y > 0)
                        {
                            v.Y = 0;
                        }
                    }

                    vs.Positions0[i] = vs.Positions[i] - v;
                }

                vs.Positions[i].Z = 0;
            }
        }
Пример #9
0
        /// <summary>
        /// Satisfies the constraint.
        /// </summary>
        /// <param name="vs">
        /// The verlet system.
        /// </param>
        /// <param name="iteration">
        /// The iteration.
        /// </param>
        public override void Satisfy(VerletIntegrator vs, int iteration)
        {
            if (this.Iterations > iteration)
            {
                Point3D x1 = vs.Positions[this.Index1];
                Point3D x2 = vs.Positions[this.Index2];
                Vector3D delta = x2 - x1;

                double deltalength = delta.Length;
                double diff = deltalength - this.Restlength;

                double div = deltalength * (vs.InverseMass[this.Index1] + vs.InverseMass[this.Index2]);

                if (Math.Abs(div) > 1e-8)
                {
                    diff /= div;
                    if (vs.InverseMass[this.Index1] != 0)
                    {
                        vs.Positions[this.Index1] += delta * diff * vs.InverseMass[this.Index1] * this.RelaxationFactor;
                    }

                    if (vs.InverseMass[this.Index2] != 0)
                    {
                        vs.Positions[this.Index2] -= delta * diff * vs.InverseMass[this.Index2] * this.RelaxationFactor;
                    }
                }
            }
        }
Пример #10
0
        public ExplodingMesh(MeshGeometry3D inputMesh, Point3D hitpos)
        {
            var mesh = MeshGeometryHelper.NoSharedVertices(inputMesh);

            double cx, cy, cz;
            cx = cy = cz = 0;
            for (int i = 0; i < mesh.Positions.Count; i++)
            {
                cx += mesh.Positions[i].X;
                cy += mesh.Positions[i].Y;
                cz += mesh.Positions[i].Z;
            }
            int n = mesh.Positions.Count;
            var center = new Point3D(cx / n, cy / n, cz / n);

            integrator = new VerletIntegrator();
            integrator.Resize(mesh.Positions.Count);
            var r = new Random();
            for (int i = 0; i < mesh.Positions.Count; i++)
            {
                var delta = mesh.Positions[i] - center;
                delta.Normalize();
                integrator.Positions[i] = mesh.Positions[i] + delta * (1 + r.NextDouble() * 2);
                integrator.Positions0[i] = mesh.Positions[i];
                integrator.Accelerations[i] = new Vector3D(0, 0, -1000);
                integrator.InverseMass[i] = 0.01;
            }

            integrator.CreateConstraintsByMesh(mesh, 0.7);
            integrator.AddFloor(0.3);
            this.Mesh = mesh;
            watch.Start();
        }