コード例 #1
0
ファイル: Physics.cs プロジェクト: giacatlaoboi/Symbolism
        // xB = xA + vAx t + 1/2 ax t^2                     (9)

        // yB = yA + vAy t + 1/2 ay t^2                     (10)

        // xB - xA = d cos th								(13)

        // yB - yA = d sin th								(14)

        // ax = 0											(11)

        // vAx = vA cos(thA)								(6)

        // vAy = vA sin(thA)								(7)


        // (9):	xB = xA + vAx t + 1/2 ax t^2

        //         xB - xA = vAx t + 1/2 ax t^2             (9.1)

        // (10):	yB = yA + vAy t + 1/2 ay t^2

        //         yB - yA = vAy t + 1/2 ay t^2             (10.1)


        // (13):		xB - xA = d cos th

        // /. (9.1)	vAx t + 1/2 ax t^2 = d cos th

        // /. (11)		vAx t = d cos th

        // t            t = d cos(th) / vAx                 (13.1)


        // (14):		yB - yA = d sin th

        // /. (10.1)	vAy t + 1/2 ay t^2 = d sin th

        // /. (13.1)	vAy [d cos(th) / vAx] + 1/2 ay [d cos(th) / vAx]^2 = d sin th

        //             vAy / vAx d cos(th) + 1/2 ay [d cos(th) / vAx]^2 = d sin th

        //             1/2 ay [d cos(th) / vAx]^2 = d sin th - vAy / vAx d cos(th)

        //             1/2 ay [d cos(th) / vAx]^2 = d [sin(th) - vAy / vAx cos(th)]

        //             1/2 ay d^2 [cos(th) / vAx]^2 = d [sin(th) - vAy / vAx cos(th)]

        //             1/2 ay d [cos(th) / vAx]^2 = [sin(th) - vAy / vAx cos(th)]

        //             d = 2 [sin(th) - vAy / vAx cos(th)] [vAx / cos(th)]^2 / ay

        // if vAy = 0 then it simplifies to:

        //             d = 2 sin(th) [vAx / cos(th)]^2 / ay

        #endregion

        public Point ProjectileInclineIntersection(MathObject theta)
        {
            if (theta != null &&
                velocity.x != null &&
                velocity.y != null &&
                acceleration.y != null &&
                acceleration.y != 0 &&
                acceleration.y != 0.0)
            {
                var d =
                    2 * (Trig.Sin(theta) - velocity.y / velocity.x * Trig.Cos(theta))
                    * ((velocity.x / Trig.Cos(theta)) ^ 2)
                    / acceleration.y;

                return
                    (new Point(
                         position.x + d * Trig.Cos(theta),
                         position.y + d * Trig.Sin(theta)));
            }

            throw new Exception();
        }
コード例 #2
0
ファイル: Physics.cs プロジェクト: giacatlaoboi/Symbolism
        public MathObject ForceMagnitude(Point f)
        {
            // 2 unknown force magnitudes
            // 0 unknown force angles

            if (forces.Count(elt => elt.magnitude == null) == 2
                &&
                forces.Count(elt => elt.angle == null) == 0)
            {
                var otherUnknownForce = forces.Find(elt => elt != f && elt.magnitude == null);

                var knownForces = new List <Point>(forces);

                knownForces.Remove(f);
                knownForces.Remove(otherUnknownForce);

                var th1 = f.angle;
                var th2 = otherUnknownForce.angle;

                var result = -acceleration.y * mass * Trig.Cos(th2) + acceleration.x * mass * Trig.Sin(th2);

                knownForces.ForEach(elt =>
                {
                    result = result - elt.magnitude * Trig.Cos(elt.angle) * Trig.Sin(th2);
                    result = result + elt.magnitude * Trig.Sin(elt.angle) * Trig.Cos(th2);
                });

                result = result / (Trig.Cos(th1) * Trig.Sin(th2) - Trig.Sin(th1) * Trig.Cos(th2));

                return(result);
            }

            // F1 = (m ay - F2 sin(th2) - F3 sin(th3) ...) / sin(th1)

            if (f.angle != null
                &&
                Trig.Sin(f.angle) != 0
                &&
                Trig.Sin(f.angle) != 0.0
                &&
                forces.Count(elt => elt.magnitude == null) == 1
                &&
                forces.Count(elt => elt.angle == null) == 0
                )
            {
                var otherForces = new List <Point>(forces);

                otherForces.Remove(f);

                var val = mass * acceleration.y;

                otherForces.ForEach(force => val = val - force.magnitude * Trig.Sin(force.angle));

                val = val / Trig.Sin(f.angle);

                return(val);
            }

            // F1 = (m ax - F2 cos(th2) - F3 cos(th3) ...) / cos(th1)

            if (f.angle != null
                &&
                Trig.Cos(f.angle) != 0
                &&
                Trig.Cos(f.angle) != 0.0
                &&
                forces.Count(elt => elt.magnitude == null) == 1
                &&
                forces.Count(elt => elt.angle == null) == 0
                )
            {
                var otherForces = new List <Point>(forces);

                otherForces.Remove(f);

                var val = mass * acceleration.x;

                otherForces.ForEach(force => val = val - force.magnitude * Trig.Cos(force.angle));

                val = val / Trig.Cos(f.angle);

                return(val);
            }

            throw new Exception();
        }
コード例 #3
0
ファイル: Physics.cs プロジェクト: giacatlaoboi/Symbolism
        //////////////////////////////////////////////////////////////////////

        public static Point FromAngle(MathObject angle, MathObject mag)
        {
            return(new Point(Trig.Cos(angle) * mag, Trig.Sin(angle) * mag));
        }