Esempio n. 1
0
        static void ClosestLine()
        {
            //Collect data from user
            Console.Write("Enter the x coordinate of the ship (km): ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate of the ship (km): ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate of the ship (km): ");
            float z = Convert.ToSingle(Console.ReadLine());
            Vector3D ship = new Vector3D(x, y, z); //km
            Console.Write("Enter the x coordinate of the meteor (km): ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate of the meteor (km): ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate of the meteor (km): ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D meteor = new Vector3D(x, y, z); //km
            Console.Write("Enter the x coordinate of the meteor's trajectory (km/s): ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate of the meteor's trajectory (km/s): ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate of the meteor's trajectory (km/s): ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D trajectory = new Vector3D(x, y, z); //km/s

            //The mathening
            Vector3D closestPoint = ship.ClosestPointLine(meteor, trajectory); //km, the closest point on the line

            //Output
            Console.WriteLine("Closest Point is: " + closestPoint + " km");
            Console.WriteLine("Distance of closest approach is: {0:N2} km", (closestPoint - ship).GetMagnitude());
        }
Esempio n. 2
0
 /// <summary>
 /// Vector Normalization
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static Vector3D operator !(Vector3D v)
 {
     if (v.GetMagnitude() == 0)
     {
         return v;
     }
     else
     {
         Vector3D toReturn = new Vector3D(v.X / v.GetMagnitude(), v.Y / v.GetMagnitude(), v.Z / v.GetMagnitude());
         return toReturn;
     }
 }
Esempio n. 3
0
        static void CenterScale(ref Vector3D[] points)
        {
            //Get the Center point for the scaling
            Console.WriteLine("Center Point to scale around:");
            Console.Write("Enter the x coordinate: ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate: ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate: ");
            float z = Convert.ToSingle(Console.ReadLine());
            Vector3D center = new Vector3D(x, y, z);

            //Get the scaling factors
            Console.WriteLine("Scaling Factors:");
            Console.Write("Enter the x direction factor: ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y direction factor: ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z direction factor: ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D scale = new Vector3D(x, y, z);

            //Scale the vertices
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = points[i].CenterScaling(scale, center);
                if (i != points.Length - 1)
                {
                    Console.WriteLine(points[i] + ", ");
                }
                else
                {
                    Console.WriteLine(points[i]);
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Subtraction of two vectors
 /// </summary>
 /// <param name="u"></param>
 /// <param name="v"></param>
 /// <returns></returns>
 public static Vector3D operator -(Vector3D u, Vector3D v)
 {
     Vector3D toReturn = new Vector3D(u.X - v.X, u.Y - v.Y, u.Z - v.Z);
     return toReturn;
 }
Esempio n. 5
0
 /// <summary>
 /// Addition of two vectors
 /// </summary>
 /// <param name="u"></param>
 /// <param name="v"></param>
 /// <returns></returns>
 public static Vector3D operator +(Vector3D u, Vector3D v)
 {
     Vector3D toReturn = new Vector3D(u.X + v.X, u.Y + v.Y, u.Z + v.Z);
     return toReturn;
 }
Esempio n. 6
0
 /// <summary>
 /// Scalar Multiplication
 /// </summary>
 /// <param name="v"></param>
 /// <param name="a"></param>
 /// <returns></returns>
 public static Vector3D operator *(Vector3D v, float a)
 {
     Vector3D toReturn = new Vector3D(a * v.X, a * v.Y, a * v.Z);
     return toReturn;
 }
Esempio n. 7
0
        static void TranslationMatrix(ref Vector3D[] points)
        {
            //Get the translation Vector
            Console.WriteLine("Translation Vector:");
            Console.Write("Enter the x coordinate: ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate: ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate: ");
            float z = Convert.ToSingle(Console.ReadLine());
            Vector3D translation = new Vector3D(x, y, z);

            //Translate the vertices
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = points[i].TranslateWithMatrix(translation);
                if (i != points.Length - 1)
                {
                    Console.WriteLine(points[i] + ", ");
                }
                else
                {
                    Console.WriteLine(points[i]);
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Check Static Friction
 /// </summary>
 /// <param name="parallelNetForce">the net force vector projected parallel to the surface</param>
 /// <param name="normalForce">the normal force vector</param>
 /// <param name="coefficientOfFriction">the coefficient of static friction</param>
 /// <returns>if the force is sufficient to overcome static friction</returns>
 public static bool CheckStaticFriction(Vector3D parallelNetForce, Vector3D normalForce, float coefficientOfFriction)
 {
     return ((coefficientOfFriction * normalForce.GetMagnitude()) < parallelNetForce.GetMagnitude());
 }
Esempio n. 9
0
 /// <summary>
 /// Get the force vector for gravity in 2D space using potential energy
 /// </summary>
 /// <param name="position">the vector from the center of the object exerting the gravity to the object examined</param>
 /// <param name="mass1"></param>
 /// <param name="mass2"></param>
 /// <param name="arbitrarySmallAmount">can be anything, so long as it is less than the anticipated movement per timestep</param>
 /// <returns></returns>
 static Vector3D GravityPEForce2D(Vector3D position, float mass1, float mass2, float arbitrarySmallAmount)
 {
     float xDirForce = (GravityPE(new Vector3D((position.X - arbitrarySmallAmount), position.Y).GetMagnitude(), mass1, mass2) - GravityPE(new Vector3D((position.X + arbitrarySmallAmount), position.Y).GetMagnitude(), mass1, mass2)) / (2 * arbitrarySmallAmount); //N
     float yDirForce = (GravityPE(new Vector3D(position.X, (position.Y - arbitrarySmallAmount)).GetMagnitude(), mass1, mass2) - GravityPE(new Vector3D(position.X, (position.Y + arbitrarySmallAmount)).GetMagnitude(), mass1, mass2)) / (2 * arbitrarySmallAmount); //N
     return new Vector3D(xDirForce, yDirForce);
 }
Esempio n. 10
0
 /// <summary>
 /// Get the point on a plane closest to the position calling it
 /// </summary>
 /// <param name="planarPoint">a point on the plane</param>
 /// <param name="planarNormal">a vector perpendicular to the plane</param>
 /// <returns>the point on the plane that is closest to the Vector3D calling the function</returns>
 public Vector3D ClosestPointPlane(Vector3D planarPoint, Vector3D planarNormal)
 {
     Vector3D pointToObject = this - planarPoint;
     return (pointToObject ^ planarNormal) + planarPoint;
 }
Esempio n. 11
0
        static void RotatingWithQuaternions()
        {
            //Collect user input
            Console.WriteLine("Enter a point:");
            Console.Write("X-coordinate: ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Y-coordinate: ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Z-coordinate: ");
            float z = Convert.ToSingle(Console.ReadLine());
            Quaternion point = new Quaternion(0, x, y, z);
            Console.WriteLine("Enter a standard position vector to rotate around:");
            Console.Write("X component: ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Y component: ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Z component: ");
            z = Convert.ToSingle(Console.ReadLine());
            Quaternion axis = new Quaternion(0, x, y, z);
            Console.Write("Enter an angle in degrees to rotate the point by: ");
            float angle = Convert.ToSingle(Console.ReadLine()); //Degrees

            //Do the rotation
            Quaternion newPoint = point.Rotation(axis, angle);
            Vector3D output = new Vector3D(newPoint.X, newPoint.Y, newPoint.Z);
            Console.WriteLine("New point as a Quaternion: " + newPoint);
            Console.WriteLine("New point as a Vector: " + output);
        }
Esempio n. 12
0
        static void RawScale(ref Vector3D[] points)
        {
            //Get the scaling factors
            Console.WriteLine("Scaling Factors:");
            Console.Write("Enter the x direction factor: ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y direction factor: ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z direction factor: ");
            float z = Convert.ToSingle(Console.ReadLine());
            Vector3D scale = new Vector3D(x, y, z);

            //Scale the vertices
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = points[i].RawScaling(scale);
                if (i != points.Length - 1)
                {
                    Console.WriteLine(points[i] + ", ");
                }
                else
                {
                    Console.WriteLine(points[i]);
                }
            }
        }
Esempio n. 13
0
        static void PlaneReflection()
        {
            //Collect User input
            Console.Write("Enter the coefficient of restitution: ");
            float coefficientOfRestitution = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the x-component of the initial velocity: ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y-component of the initial velocity: ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z-component of the initial velocity: ");
            float z = Convert.ToSingle(Console.ReadLine());
            Vector3D velocity = new Vector3D(x, y, z);
            Console.Write("Enter the x-component of the first planar vector: ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y-component of the first planar vector: ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z-component of the first planar vector: ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D plane1 = new Vector3D(x, y, z);
            Console.Write("Enter the x-component of the second planar vector: ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y-component of the second planar vector: ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z-component of the second planar vector: ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D plane2 = new Vector3D(x, y, z);

            //get the normalized planar normal
            Vector3D normal = !(plane1 % plane2);

            //Get the final velocity
            Vector3D finalVelocity = velocity - ((1 + coefficientOfRestitution) * (normal * velocity)) * normal;
            //Display the final velocity
            Console.WriteLine("New velocity is " + finalVelocity.ToString());
        }
Esempio n. 14
0
        static void Orbit()
        {
            //giant block o' variables
            Console.Write("Input initial speed in km/s: ");
            Vector3D velocity = new Vector3D(Convert.ToSingle(Console.ReadLine()) * 1000f, 0); //m/s
            Vector3D position = new Vector3D(0, 6778000f); //m
            float massOfSpacecraft = 225f; //kg
            float inverseMassOfSpacecraft = 1 / massOfSpacecraft; //1/kg
            float massOfEarth = 5.98e24f; //kg
            float radiusOfEarth = 6378000f; //m
            float atmosphereRadius = 6478000f; //m
            int timeStep = 10; //s
            float arbitrarySmallAmount = 1f; //m
            float altitude = (position.Y - radiusOfEarth) / 1000f; //km
            float speed = velocity.X / 1000f; //km/s
            float totalEnergy = (massOfSpacecraft * speed * speed * 500000f) + GravityPE(position.GetMagnitude(), massOfSpacecraft, massOfEarth); //N
            Vector3D acceleration = inverseMassOfSpacecraft * GravityPEForce2D (position, massOfSpacecraft, massOfEarth, arbitrarySmallAmount); //m/(s^2)
            Console.WriteLine("Time: {0:N}s, Altitude: {1:N2}km,\nSpeed: {2:N2}km/s,\nTotal energy: {3:N2}N Acceleration: " + acceleration.PrintRect(), 0, altitude, speed, totalEnergy);

            //start simulation loop
            for (int time = 0; time < 36000 && position.GetMagnitude() > atmosphereRadius; time += timeStep) //time is in seconds
            {
                position += velocity * timeStep; //update position
                velocity += acceleration * timeStep; //update velocity
                acceleration = inverseMassOfSpacecraft * GravityPEForce2D(position, massOfSpacecraft, massOfEarth, arbitrarySmallAmount); //update acceleration

                //calculate and display output
                altitude = (position.GetMagnitude() - radiusOfEarth) / 1000f;
                speed = velocity.GetMagnitude() / 1000f;
                totalEnergy = (massOfSpacecraft * speed * speed * 500000f) + GravityPE(position.GetMagnitude(), massOfSpacecraft, massOfEarth);
                Console.WriteLine("Time: {0:N}s, Altitude: {1:N2}km,\nSpeed: {2:N2}km/s,\nTotal energy: {3:N2}N", time, altitude, speed, totalEnergy);

            }
            if (position.GetMagnitude() <= atmosphereRadius)
            {
                Console.WriteLine("Crashed into atmosphere! Go faster next time!");
            }
        }
Esempio n. 15
0
 static void ModelRocket()
 {
     //Giant pile of Variables
     Vector3D position = new Vector3D(0, 0, .2f); //meters
     float inverseMass = 1 / .0742f; //kilograms
     float coefficientOfWindResistance = .02f;
     Vector3D thrustForce = Vector3D.zero;
     thrustForce.SetRectGivenMagHeadPitch(10f, 23f, 62f); //newtons
     Console.WriteLine(Vector3D.zero.PrintRect());
     Vector3D thrustAcc = inverseMass * thrustForce; //m/(s^2)
     Vector3D velocity = Vector3D.zero;
     Vector3D gravityAcc = new Vector3D(0f, 0f, -9.8f); //m/(s^2)
     Vector3D acceleration = gravityAcc + thrustAcc; //m/(s^2)
     float timeStep = .1f; //seconds
     float time = 0f; //seconds
     while (time < 1f) //under thrust
     {
         position = position + timeStep * velocity;
         velocity = velocity + timeStep * acceleration;
         acceleration = gravityAcc + thrustAcc - (velocity * (coefficientOfWindResistance * inverseMass));
         time += timeStep;
         Console.WriteLine(position.PrintRect() + " " + velocity.PrintRect() + " " + time);
     }
     while (position.Z > 0) //post thrust
     {
         position = position + timeStep * velocity;
         velocity = velocity + timeStep * acceleration;
         acceleration = gravityAcc - (velocity * (coefficientOfWindResistance * inverseMass));
         time += timeStep;
     }
     Console.WriteLine("Rocket lands at ({0:N2}, {1:N2}) m after {2:N2} seconds of flight.", position.X, position.Y, time);
 }
Esempio n. 16
0
 /// <summary>
 /// Get the force vector for gravity in 3D space using potential energy
 /// </summary>
 /// <param name="position">the vector from the center of the object exerting the gravity to the object examined</param>
 /// <param name="mass1"></param>
 /// <param name="mass2"></param>
 /// <param name="arbitrarySmallAmount">can be anything, so long as it is less than the anticipated movement per timestep</param>
 /// <returns></returns>
 static Vector3D GravityPEForce3D(Vector3D position, float mass1, float mass2, float arbitrarySmallAmount)
 {
     float xDirForce = (GravityPE((position.X - arbitrarySmallAmount), mass1, mass2) - GravityPE((position.X + arbitrarySmallAmount), mass1, mass2)) / (2 * arbitrarySmallAmount); //N
     float yDirForce = (GravityPE((position.Y - arbitrarySmallAmount), mass1, mass2) - GravityPE((position.Y + arbitrarySmallAmount), mass1, mass2)) / (2 * arbitrarySmallAmount); //N
     float zDirForce = (GravityPE((position.Z - arbitrarySmallAmount), mass1, mass2) - GravityPE((position.Z + arbitrarySmallAmount), mass1, mass2)) / (2 * arbitrarySmallAmount); //N
     return new Vector3D(xDirForce, yDirForce, zDirForce);
 }
Esempio n. 17
0
 public Vector3D CenterScaling(Vector3D scale, Vector3D center)
 {
     //Create Matrix
     Vector3D[] matrix = new Vector3D[4];
     matrix[0] = new Vector3D(scale.X, 0, 0, center.X * (1 - scale.X));
     matrix[1] = new Vector3D(0, scale.Y, 0, center.Y * (1 - scale.Y));
     matrix[2] = new Vector3D(0, 0, scale.Z, center.Z * (1 - scale.Z));
     matrix[3] = new Vector3D(0, 0, 0, 1);
     //Matrix Multiplication
     return new Vector3D(Dot4(matrix[0]), Dot4(matrix[1]), Dot4(matrix[2]), Dot4(matrix[3]));
 }
Esempio n. 18
0
 public Vector3D RawScaling(Vector3D scale)
 {
     //Create Matrix
     Vector3D[] matrix = new Vector3D[4];
     matrix[0] = new Vector3D(scale.X, 0, 0, 0);
     matrix[1] = new Vector3D(0, scale.Y, 0, 0);
     matrix[2] = new Vector3D(0, 0, scale.Z, 0);
     matrix[3] = new Vector3D(0, 0, 0, 1);
     //Matrix Multiplication
     return new Vector3D(Dot4(matrix[0]), Dot4(matrix[1]), Dot4(matrix[2]), Dot4(matrix[3]));
 }
Esempio n. 19
0
 /// <summary>
 /// Get the point on a line closest to the position calling it
 /// </summary>
 /// <param name="linePoint"> a point on the line</param>
 /// <param name="lineDirection">a vector describing the direction of the line</param>
 /// <returns>the point on the line that is closest to the Vector3D calling the function</returns>
 public Vector3D ClosestPointLine(Vector3D linePoint, Vector3D lineDirection)
 {
     Vector3D pointToObject = this - linePoint;
     return (pointToObject | lineDirection) + linePoint;
 }
Esempio n. 20
0
 public Vector3D TranslateWithMatrix(Vector3D translation)
 {
     //Create Matrix
     Vector3D[] matrix = new Vector3D[4];
     matrix[0] = new Vector3D(1, 0, 0, translation.X);
     matrix[1] = new Vector3D(0, 1, 0, translation.Y);
     matrix[2] = new Vector3D(0, 0, 1, translation.Z);
     matrix[3] = new Vector3D(0, 0, 0, 1);
     //Matrix Multiplication
     return new Vector3D(Dot4(matrix[0]), Dot4(matrix[1]), Dot4(matrix[2]), Dot4(matrix[3]));
 }
Esempio n. 21
0
 /// <summary>
 /// Dot product using all four values
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public float Dot4(Vector3D other)
 {
     return (this * other + W * other.W);
 }
Esempio n. 22
0
        static void ClosestPlane()
        {
            //Collect data from user
            Console.Write("Enter the x coordinate of the ship (km): ");
            float x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate of the ship (km): ");
            float y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate of the ship (km): ");
            float z = Convert.ToSingle(Console.ReadLine());
            Vector3D ship = new Vector3D(x, y, z); //km
            Console.WriteLine("First planar point:");
            Console.Write("Enter the x coordinate (km): ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate (km): ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate (km): ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D point1 = new Vector3D(x, y, z); //km
            Console.WriteLine("Second planar point:");
            Console.Write("Enter the x coordinate (km): ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate (km): ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate (km): ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D point2 = new Vector3D(x, y, z); //km
            Console.WriteLine("Third planar point:");
            Console.Write("Enter the x coordinate (km): ");
            x = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the y coordinate (km): ");
            y = Convert.ToSingle(Console.ReadLine());
            Console.Write("Enter the z coordinate (km): ");
            z = Convert.ToSingle(Console.ReadLine());
            Vector3D point3 = new Vector3D(x, y, z); //km

            if (point1 == point2 || point2 == point3 || point3 == point1) //check if points are the same
            {
                Console.WriteLine("Error: Redundant points entered.");
            }
            else
            {
                //The mathening
                Vector3D point1To2 = point2 - point1; //km, one vector within the plane
                Vector3D point1To3 = point3 - point1; //km, another vector within the plane

                if ((!point1To2) == (!point1To3) || (!point1To2) == -1 * (!point1To3)) //check if points are on a single line
                {
                    Console.WriteLine("Error: Collinear points entered.");
                }
                else
                {
                    Vector3D normal = !(point1To2 % point1To3); //the planar normal, normalized to remove units
                    Vector3D closestPoint = ship.ClosestPointPlane(point1, normal); //km, the closest point on the plane

                    //Output
                    Console.WriteLine("Closest Point is: " + closestPoint + " km");
                    Console.WriteLine("Distance of closest approach is: {0:N2} km", (closestPoint - ship).GetMagnitude());
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Rotate the Vector around the z-axis
        /// </summary>
        /// <param name="angle">Angle of rotation in degrees</param>
        /// <returns>Vector3D after the rotation</returns>
        public Vector3D RotationAroundZ(float angle)
        {
            //Convert angle to radians and calculate sine & cosine
            angle = Deg2Rad(angle); //radians
            float cosTheta = (float)Math.Cos(angle); //distance ratio, arbitrary unit
            float sinTheta = (float)Math.Sin(angle); //distance ratio, arbitrary unit

            //Create Matrix
            Vector3D[] matrix = new Vector3D[4];
            matrix[0] = new Vector3D(cosTheta, -sinTheta, 0, 0);
            matrix[1] = new Vector3D(sinTheta, cosTheta, 0, 0);
            matrix[2] = new Vector3D(0, 0, 1, 0);
            matrix[3] = new Vector3D(0, 0, 0, 1);
            //Matrix Multiplication
            return new Vector3D(Dot4(matrix[0]), Dot4(matrix[1]), Dot4(matrix[2]), Dot4(matrix[3]));
        }
Esempio n. 24
0
        static void RotationalDynamics()
        {
            //Giant block o' pre-defined variables
            float rotation = 0; // rad
            float angularVelocity = 0f; // rad/s
            float angularAcceleration = 0; // rad/(s^2)
            float momentOfInertia = .11809f; // kg*(m^2)
            float time = 0; // s
            float deltaTime = .01f; // s
            int reportingFrequency = 10; // timesteps
            Vector3D position = Vector3D.zero; // m
            Vector3D linearVelocity = Vector3D.zero; // m/s
            Vector3D linearAcceleration = Vector3D.zero; // m/(s^2)
            Vector3D massOneLocalPosition = new Vector3D(-.28f, 0f); //m
            Vector3D massTwoLocalPosition = new Vector3D(.07f, 0f); //m

            //Collect user input
            Console.Write("Input the magnitude of the force in Newtons: ");
            Vector3D force = new Vector3D(); // N
            force.SetRectGivenMagHeadPitch(Convert.ToSingle(Console.ReadLine()), 30); //Set the rectangular coordinates of the force vector
            Console.Write("Input the number of seconds the force will be applied for: ");
            float forceDuration = Convert.ToSingle(Console.ReadLine()); // s
            linearAcceleration = force * (1 / 6.1f);
            float torque = massOneLocalPosition.X * force.Y - massOneLocalPosition.Y * force.X; // N*m
            angularAcceleration = torque / momentOfInertia;
            Vector3D massOneRotated = Vector3D.zero; // m
            Vector3D massTwoRotated = Vector3D.zero; // m
            using (StreamWriter writer = new StreamWriter("..\\..\\rotationalDynamics.csv"))
            {
                while (time <= forceDuration)
                {
                    for (int i = 0; i < reportingFrequency && time <= forceDuration; i++)
                    {
                        //increment time
                        time += deltaTime;
                        //update position & rotation
                        position += linearVelocity * deltaTime;
                        rotation += angularVelocity * deltaTime;
                        //update velocities
                        linearVelocity += linearAcceleration * deltaTime;
                        angularVelocity += angularAcceleration * deltaTime;
                        //calculate mass positions relative to center of mass
                        massOneRotated = massOneLocalPosition.RotationAroundZ(Vector3D.Rad2Deg(rotation));
                        massTwoRotated = massTwoLocalPosition.RotationAroundZ(Vector3D.Rad2Deg(rotation));
                        //recalculate torque
                        torque = massOneRotated.X * force.Y - massOneRotated.Y * force.X;
                        //update angularAcceleration
                        angularAcceleration = torque / momentOfInertia;
                        //write data to file
                        writer.WriteLine(rotation + "," + position.X + "," + position.Y + "," +
                                        (position.X + massOneRotated.X) + "," + (position.Y + massOneRotated.Y) + "," +
                                        (position.X + massTwoRotated.X) + "," + (position.Y + massTwoRotated.Y));
                    }
                    //Display positions
                    Console.WriteLine();
                    Console.WriteLine("Angle: " + rotation);
                    Console.WriteLine("Center Mass: " + position);
                    Console.WriteLine("Smaller Mass: " + (massOneRotated + position));
                    Console.WriteLine("Larger Mass: " + (massTwoRotated + position));
                }
            }
        }
Esempio n. 25
0
        static void RotationZ(ref Vector3D[] points)
        {
            //Get the angle of rotation
            Console.Write("Enter the angle of rotation (in degrees): ");
            float angle = Convert.ToSingle(Console.ReadLine());

            //Translate the vertices
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = points[i].RotationAroundZ(angle);
                if (i != points.Length - 1)
                {
                    Console.WriteLine(points[i] + ", ");
                }
                else
                {
                    Console.WriteLine(points[i]);
                }
            }
        }
Esempio n. 26
0
        static void ScalingAndTranslations()
        {
            //Get the initial object positions
            Console.Write("How many points are on the object? ");
            Vector3D[] points = new Vector3D[Convert.ToInt32(Console.ReadLine())];
            float x;
            float y;
            float z;
            for (int i = 0; i < points.Length; i++)
            {
                switch (i)
                {
                    case 0:
                        Console.WriteLine("1st point:");
                        break;
                    case 1:
                        Console.WriteLine("2nd point:");
                        break;
                    case 2:
                        Console.WriteLine("3rd point:");
                        break;
                    default:
                        Console.WriteLine((i + 1) + "th point:");
                        break;
                }
                Console.Write("Enter the x coordinate: ");
                x = Convert.ToSingle(Console.ReadLine());
                Console.Write("Enter the y coordinate: ");
                y = Convert.ToSingle(Console.ReadLine());
                Console.Write("Enter the z coordinate: ");
                z = Convert.ToSingle(Console.ReadLine());
                points[i] = new Vector3D(x, y, z);
            }

            //Do translations until terminated by user
            string menuChoice;
            do
            {
                Console.Clear();
                Console.WriteLine("Menu:");
                Console.WriteLine("[1]: Matrix Translation");
                Console.WriteLine("[2]: Raw Scaling");
                Console.WriteLine("[3]: Center Scaling");
                Console.WriteLine("[4]: Quit");
                Console.Write("Input your selection: ");
                menuChoice = Console.ReadLine();

                switch (menuChoice)
                {
                    case "1":
                        TranslationMatrix(ref points);
                        break;
                    case "2":
                        RawScale(ref points);
                        break;
                    case "3":
                        CenterScale(ref points);
                        break;
                }
                Console.Write("Press any key to continue...");
                Console.ReadKey();
            } while (menuChoice != "4");
        }
Esempio n. 27
0
 /// <summary>
 /// Kinetic Friction
 /// </summary>
 /// <param name="velocity">velocity vector</param>
 /// <param name="normalForce">normal force vector</param>
 /// <param name="coefficientOfFriction">the coefficient of kinetic friction</param>
 /// <returns>kinetic friction force vector</returns>
 public static Vector3D KineticFriction(Vector3D velocity, Vector3D normalForce, float coefficientOfFriction)
 {
     return ((-coefficientOfFriction * normalForce.GetMagnitude()) * (!velocity));
 }
Esempio n. 28
0
        static void SlidingBox()
        {
            //Giant pile of variables, assuming mass == 1
            float timeStep = .1f; //seconds
            float time = 0; //seconds
            Vector3D normalForce = new Vector3D(0, 0, 9.8f); //newtons
            Console.Write("Input an initial speed (m/s): ");
            float speed = Convert.ToSingle(Console.ReadLine());
            Vector3D velocity = new Vector3D(speed, 0); //m/s

            Console.Write("Input the coefficient of kinetic friction: ");
            float coefficientOfKineticFriction = Convert.ToSingle(Console.ReadLine());
            Vector3D friction = MPGPhysics.KineticFriction(velocity, normalForce, coefficientOfKineticFriction); //newtons
            float position = 0f; //meters
            while (-friction.X * timeStep <= speed) //check if velocity will be zero at end of time step
            {
                position = position + (speed * timeStep);
                speed = speed + (friction.X * timeStep);
                time += timeStep;
            }
            Console.WriteLine("Box stops after {0:N2} seconds, {1:N2} meters away", time, position);
        }