コード例 #1
0
        Molecule2 molecule2Creator(Atom atom1, Atom atom2, double bondLength)
        {
            Molecule2 molecule = new Molecule2();

            molecule.bondLength = bondLength;
            atom2.position      = atom1.position;
            atom2.position.X   += bondLength;
            if (atom2.position.X > size.X)
            {
                atom2.position.X -= 2 * bondLength;
            }
            return(molecule);
        }
コード例 #2
0
        void Molecule2Computer(Molecule2 molecule)
        {
            molecule.position = AddVector(molecule.position, ScalarMultiple(timeIncrement, molecule.velocity));
            double reducedMass;

            reducedMass = molecule.atom1.mass * molecule.atom2.mass / molecule.mass;
            Dvector r = ScalarMultiple(molecule.atom1.mass / molecule.mass, AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));

            molecule.interiaTensor[0, 0] = (Math.Pow(molecule.position.Y - molecule.atom1.position.Y, 2) + Math.Pow(molecule.position.Z - molecule.atom1.position.Z, 2)) * molecule.atom1.mass
                                           + (Math.Pow(molecule.position.Y - molecule.atom2.position.Y, 2) + Math.Pow(molecule.position.Z - molecule.atom2.position.Z, 2)) * molecule.atom2.mass;
            molecule.interiaTensor[1, 1] = (Math.Pow(molecule.position.X - molecule.atom1.position.X, 2) + Math.Pow(molecule.position.Z - molecule.atom1.position.Z, 2)) * molecule.atom1.mass
                                           + (Math.Pow(molecule.position.X - molecule.atom2.position.X, 2) + Math.Pow(molecule.position.Z - molecule.atom2.position.Z, 2)) * molecule.atom2.mass;
            molecule.interiaTensor[2, 2] = (Math.Pow(molecule.position.X - molecule.atom1.position.X, 2) + Math.Pow(molecule.position.Y - molecule.atom1.position.Y, 2)) * molecule.atom1.mass
                                           + (Math.Pow(molecule.position.X - molecule.atom2.position.X, 2) + Math.Pow(molecule.position.Y - molecule.atom2.position.Y, 2)) * molecule.atom2.mass;

            molecule.interiaTensor[1, 0] = (molecule.position.X - molecule.atom1.position.X) * (molecule.atom1.position.Y - molecule.position.Y) * molecule.atom1.mass + (molecule.position.X - molecule.atom2.position.X) * (molecule.atom2.position.Y - molecule.position.Y) * molecule.atom2.mass;
            molecule.interiaTensor[2, 0] = (molecule.position.X - molecule.atom1.position.X) * (molecule.atom1.position.Z - molecule.position.Z) * molecule.atom1.mass + (molecule.position.X - molecule.atom2.position.X) * (molecule.atom2.position.Z - molecule.position.Z) * molecule.atom2.mass;
            molecule.interiaTensor[2, 1] = (molecule.position.Y - molecule.atom1.position.Y) * (molecule.atom1.position.Z - molecule.position.Z) * molecule.atom1.mass + (molecule.position.Y - molecule.atom2.position.Y) * (molecule.atom2.position.Z - molecule.position.Z) * molecule.atom2.mass;

            molecule.interiaTensor[0, 1] = molecule.interiaTensor[1, 0];
            molecule.interiaTensor[0, 2] = molecule.interiaTensor[2, 0];

            molecule.interiaTensor[1, 2] = molecule.interiaTensor[2, 1];

            if (molecule.atom1.position.X > size.X || molecule.atom1.position.X < 0)
            {
                molecule.atom1.velocity.X = -molecule.atom1.velocity.X;
                molecule.velocity.X      += molecule.atom1.velocity.X * 2 * (molecule.atom1.mass) / molecule.mass;

                molecule.amplitude        = Math.Abs(2 * molecule.atom1.velocity.X / Math.Sqrt(molecule.bondSpringConstant * reducedMass));
                molecule.angularFrequency = Math.Sqrt(molecule.bondSpringConstant * reducedMass);
                molecule.theta            = Math.PI / 2;

                molecule.angularVelocity = Crossproduct(ScalarMultiple(2, molecule.atom1.velocity), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
            }
            if (molecule.atom1.position.Y > size.Y || molecule.atom1.position.Y < 0)
            {
                molecule.atom1.velocity.Y = -molecule.atom1.velocity.Y;
                molecule.velocity.Y      += molecule.atom1.velocity.Y * 2 * (molecule.atom1.mass) / molecule.mass;

                molecule.amplitude        = Math.Abs(2 * molecule.atom1.velocity.Y / Math.Sqrt(molecule.bondSpringConstant * reducedMass));
                molecule.angularFrequency = Math.Sqrt(molecule.bondSpringConstant * reducedMass);
                molecule.theta            = Math.PI / 2;

                molecule.angularVelocity = Crossproduct(ScalarMultiple(2, molecule.atom1.velocity), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
            }
            if (molecule.atom1.position.Z > size.Z || molecule.atom1.position.Z < 0)
            {
                molecule.atom1.velocity.Z = -molecule.atom1.velocity.Z;
                molecule.velocity.Z      += molecule.atom1.velocity.Z * 2 * (molecule.atom1.mass) / molecule.mass;

                molecule.amplitude        = Math.Abs(2 * molecule.atom1.velocity.Z / Math.Sqrt(molecule.bondSpringConstant * reducedMass));
                molecule.angularFrequency = Math.Sqrt(molecule.bondSpringConstant * reducedMass);
                molecule.theta            = Math.PI / 2;

                molecule.angularVelocity = Crossproduct(ScalarMultiple(2, molecule.atom1.velocity), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
            }

            if (molecule.atom2.position.X > size.X || molecule.atom2.position.X < 0)
            {
                molecule.atom2.velocity.X = -molecule.atom2.velocity.X;
                molecule.velocity.X      += molecule.atom2.velocity.X * 2 * (molecule.atom2.mass) / molecule.mass;

                molecule.amplitude        = Math.Abs(2 * molecule.atom2.velocity.X / Math.Sqrt(molecule.bondSpringConstant * reducedMass));
                molecule.angularFrequency = Math.Sqrt(molecule.bondSpringConstant * reducedMass);
                molecule.theta            = Math.PI / 2;

                molecule.angularVelocity = Crossproduct(ScalarMultiple(2, molecule.atom1.velocity), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
            }
            if (molecule.atom2.position.Y > size.Y || molecule.atom2.position.Y < 0)
            {
                molecule.atom2.velocity.Y = -molecule.atom2.velocity.Y;
                molecule.velocity.Y      += molecule.atom2.velocity.Y * 2 * (molecule.atom2.mass) / molecule.mass;

                molecule.amplitude        = Math.Abs(2 * molecule.atom2.velocity.Y / Math.Sqrt(molecule.bondSpringConstant * reducedMass));
                molecule.angularFrequency = Math.Sqrt(molecule.bondSpringConstant * reducedMass);
                molecule.theta            = Math.PI / 2;

                molecule.angularVelocity = Crossproduct(ScalarMultiple(2, molecule.atom1.velocity), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
            }
            if (molecule.atom2.position.Z > size.Z || molecule.atom2.position.Z < 0)
            {
                molecule.atom2.velocity.Z = -molecule.atom2.velocity.Z;
                molecule.velocity.Z      += molecule.atom2.velocity.Z * 2 * (molecule.atom2.mass) / molecule.mass;

                molecule.amplitude        = Math.Abs(2 * molecule.atom2.velocity.Z / Math.Sqrt(molecule.bondSpringConstant * reducedMass));
                molecule.angularFrequency = Math.Sqrt(molecule.bondSpringConstant * reducedMass);
                molecule.theta            = Math.PI / 2;

                molecule.angularVelocity = Crossproduct(ScalarMultiple(2, molecule.atom1.velocity), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
            }

            foreach (Atom atom in atoms)
            {
                if (molecule.atom1 != atom && AbsVect(AddVector(atom.position, ScalarMultiple(-1, molecule.atom1.position))) < atom.radius + molecule.atom1.radius)
                {
                    Collision(molecule.atom1, atom);
                    molecule.angularVelocity = Crossproduct(AddVector(molecule.atom1.velocity, ScalarMultiple(-1, molecule.atom2.velocity)), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
                }

                if (molecule.atom2 != atom && AbsVect(AddVector(atom.position, ScalarMultiple(-1, molecule.atom2.position))) < atom.radius + molecule.atom2.radius)
                {
                    Collision(molecule.atom2, atom);
                    molecule.angularVelocity = Crossproduct(AddVector(molecule.atom1.velocity, ScalarMultiple(-1, molecule.atom2.velocity)), AddVector(molecule.atom1.position, ScalarMultiple(-1, molecule.atom2.position)));
                }
            }

            molecule.angularVelocity   = Crossproduct(AddVector(molecule.atom2.velocity, ScalarMultiple(-1, molecule.atom1.velocity)), AddVector(molecule.atom2.velocity, ScalarMultiple(-1, molecule.atom1.velocity)));
            molecule.AngularMomentum.X = molecule.interiaTensor[0, 0] * molecule.angularVelocity.X + molecule.interiaTensor[0, 1] * molecule.angularVelocity.Y + molecule.interiaTensor[0, 2] * molecule.angularVelocity.Z;
            molecule.AngularMomentum.Y = molecule.interiaTensor[1, 0] * molecule.angularVelocity.X + molecule.interiaTensor[1, 1] * molecule.angularVelocity.Y + molecule.interiaTensor[1, 2] * molecule.angularVelocity.Z;
            molecule.AngularMomentum.Z = molecule.interiaTensor[2, 0] * molecule.angularVelocity.X + molecule.interiaTensor[2, 1] * molecule.angularVelocity.Y + molecule.interiaTensor[2, 2] * molecule.angularVelocity.Z;
        }
コード例 #3
0
        void Molecule2ComputerDelegate(object Molecule2Delegate)
        {
            Molecule2 molecule = (Molecule2)Molecule2Delegate;

            Molecule2Computer(molecule);
        }