Esempio n. 1
0
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.yellow;
        Gizmos.DrawSphere(transform.position + transform.TransformDirection(Rb.centerOfMass), 0.3f);
        Gizmos.color = Color.blue;
        Vector3 centerOfLift = new Vector3();
        float   totalLift    = 0;

        foreach (VehiclePart part in Parts)
        {
            Aerodynamics aerodynamics = new Aerodynamics();
            if (part.Type == VehiclePartType.MoveableStructural)
            {
                aerodynamics = ((TMoveableStructure)part).Aerodynamics;
            }
            else if (part.Type == VehiclePartType.Structural)
            {
                aerodynamics = ((TStructuralPart)part).Aerodynamics;
            }

            Vector3 worldAC   = transform.position + transform.TransformDirection(aerodynamics.LocalAerodynamicCenter);
            float   magnitude = aerodynamics.LiftVector.magnitude;
            centerOfLift += magnitude * worldAC;
            totalLift    += magnitude;
        }
        centerOfLift /= totalLift;
        Gizmos.DrawSphere(centerOfLift, 0.3f);
    }
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.yellow;
        //Gizmos.DrawSphere(transform.position + transform.TransformDirection(Rb.centerOfMass), 0.3f);
        Gizmos.DrawSphere(transform.position + transform.TransformDirection(CenterOfMass), 0.3f);
        Gizmos.color = Color.blue;
        Vector3 centerOfLift = new Vector3();
        float   totalLift    = 0;

        foreach (VehiclePart part in Parts)
        {
            if (part is IAerodynamicPart)
            {
                Aerodynamics aerodynamics = (part as IAerodynamicPart).Aerodynamics;

                Vector3 worldAC          = aerodynamics.GetAdjustedWorldAerodynamicCenter(part); //part.transform.position + part.transform.TransformDirection(aerodynamics.LocalAerodynamicCenter);
                Vector3 relativePosition = worldAC - transform.position;
                float   magnitude        = aerodynamics.LiftVector.magnitude;
                centerOfLift += magnitude * relativePosition;
                totalLift    += magnitude;
            }
        }
        centerOfLift /= totalLift;
        Gizmos.DrawSphere(centerOfLift + transform.position, 0.3f);
    }
Esempio n. 3
0
        public void CorrectGetAerodynamicsByString(string input)
        {
            var pilots = new Mock <ICarServices>();
            var parts  = new Aerodynamics
            {
                Name      = "Aerodynamics",
                Price     = 100,
                Speed     = 40,
                Strength  = 50,
                IsDeleted = false,
            };

            pilots.Setup(x => x.GetAerodynamics(It.IsAny <string>()))
            .Returns(parts);

            var result      = pilots.Object.GetAerodynamics(input);
            var resultName  = result.Name;
            var resultPrice = result.Price;
            var resultSpeed = result.Speed;
            var resultId    = result.IsDeleted;

            Assert.Equal(false, resultId);
            Assert.Equal(40, resultSpeed);
            Assert.Equal(100, resultPrice);
            Assert.Equal("Aerodynamics", resultName);
        }
Esempio n. 4
0
        public string GetLogMessage()
        {
            return(string.Format(@"------------- Simulation ------------
{0}
{1}
{2}
{3}
{4}
{5}
{6}
{7}
{8}
{9}
------------- Simulation ------------",
                                 this.ToLogMessage(),
                                 Acceleration.ToLogMessage(),
                                 Aerodynamics.ToLogMessage(),
                                 Atmosphere.ToLogMessage(),
                                 Control.ToLogMessage(),
                                 Control.ControlInterval.ToLogMessage(),
                                 Control.QAlpha.ToLogMessage(),
                                 Coordinates.ToLogMessage(),
                                 Pitch.ToLogMessage(),
                                 Velocity.ToLogMessage()));
        }
Esempio n. 5
0
        private void OnCoordinatesParsed(object source, CoordinatesParsedEventArgs args)
        {
            Vector vInfinity = new Vector(new double[] {
                Math.Cos(args.AOA) * Math.Cos(args.AOY) * args.MagnitudeOfVInfinity,
                -Math.Sin(args.AOY) * args.MagnitudeOfVInfinity,
                Math.Sin(args.AOA) * Math.Cos(args.AOY) * args.MagnitudeOfVInfinity
            });

            // Parse the airfoil file for the 2-dimensional coordinates of the camber line
            double[,] camberLine = AirfoilGeometryApproximator.GetCamberLine(args.Coordinates,
                                                                             args.NumberOfTilesChordwise + 1);

            // Generate an array of wing tiles
            WingTile[] wingTiles = AirfoilGeometryApproximator.GetWingTiles(camberLine,
                                                                            args.Chord,
                                                                            args.WingSpan,
                                                                            args.NumberOfTilesSpanwise);

            // Generate a matrix with the aerodynamic linear equations
            Matrix <double> EquationMatrix = Aerodynamics.ConstructAICCirculationEquationMatrix(wingTiles, vInfinity);

            // Solve said equations for gammas (vorticities) with Gaussian elimination
            double[] gammas = Matrix <double> .SolveWithGaussianElimination(EquationMatrix);

            // Get the total aerodynamic reaction.
            Vector[] forces = Aerodynamics.GetForces(wingTiles, vInfinity, gammas, args.Rho);

            Vector totalForce = Aerodynamics.GetTotalForce(forces);

            Vector totalMoment = Aerodynamics.GetTotalMoment(new Vector(new double[] {
                args.Chord / 4,
                args.WingSpan / 2,
                0
            }),
                                                             forces,
                                                             wingTiles);

            // Get the magnitude of the lift and drag forces.
            double lift        = totalForce.Coordinates[2] * Math.Cos(args.AOA) - totalForce.Coordinates[0] * Math.Sin(args.AOA);
            double inducedDrag = totalForce.Coordinates[2] * Math.Sin(args.AOA) + totalForce.Coordinates[0] * Math.Cos(args.AOA);

            // Get the coefficient of lift.
            double factor = 2 / (args.Rho * vInfinity.MagS * args.WingSpan * args.Chord);
            double CL     = factor * lift;
            double CDI    = factor * inducedDrag;
            double CM     = factor * totalMoment.Coordinates[1] / args.Chord;

            // Display
            Console.WriteLine("-------------------------  Data  -----------------------------");
            Console.WriteLine($"CL = {CL}");

            SimulationComplete?.Invoke(this, new SimulationCompleteEventArgs(camberLine,
                                                                             wingTiles,
                                                                             forces,
                                                                             CL,
                                                                             CDI,
                                                                             CM));
        }
Esempio n. 6
0
    // Initialisation
    private void Start()
    {
        im     = GetComponent <InputManager>();
        rb     = GetComponent <Rigidbody>();
        ty     = GetComponent <Tyres>();
        engine = GetComponent <Engine>();
        trans  = GetComponent <Transmission>();
        aero   = GetComponent <Aerodynamics>();
        brakes = GetComponent <Brakes>();
        diff   = GetComponent <Differential>();
        steer  = GetComponent <Steering>();
        wheels = GetComponent <Wheels>();

        if (CM)
        {
            rb.centerOfMass = CM.localPosition;
        }
    }
Esempio n. 7
0
        private bool Allocate()
        {
            bool result = true;

            atmosphere      = new Atmosphere(this);
            propulsion      = new Propulsion(this);
            aerodynamics    = new Aerodynamics(this);
            FCS             = new FlightControlSystem(this);
            groundReactions = new GroundReactions(this);
            inertial        = new Inertial(this);
            massBalance     = new MassBalance(this);
            propagate       = new Propagate(this);
            auxiliary       = new Auxiliary(this);
            aircraft        = new Aircraft(this);
            //output = new Output(this);
            input          = new Input(this);
            groundCallback = new GroundCallback();
            state          = new State(this); // This must be done here, as the State
            // class needs valid pointers to the above model classes


            // Initialize models so they can communicate with each other

            if (!atmosphere.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Atmosphere model init failed");
                }
                error += 1;
            }
            if (!FCS.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("FCS model init failed");
                }
                error += 2;
            }
            if (!propulsion.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Propulsion model init failed");
                }
                error += 4;
            }
            if (!massBalance.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("MassBalance model init failed");
                }
                error += 8;
            }
            if (!aerodynamics.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Aerodynamics model init failed");
                }
                error += 16;
            }
            if (!inertial.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Inertial model init failed");
                }
                error += 32;
            }
            if (!groundReactions.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Ground Reactions model init failed");
                }
                error += 64;
            }
            if (!aircraft.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Aircraft model init failed");
                }
                error += 128;
            }
            if (!propagate.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Propagate model init failed");
                }
                error += 256;
            }
            if (!auxiliary.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Auxiliary model init failed");
                }
                error += 512;
            }
            if (!input.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Intput model init failed");
                }
                error += 1024;
            }

            if (error > 0)
            {
                result = false;
            }

            ic = new InitialCondition(this);

            // Schedule a model. The second arg (the integer) is the pass number. For
            // instance, the atmosphere model gets executed every fifth pass it is called
            // by the executive. Everything else here gets executed each pass.
            // IC and Trim objects are NOT scheduled.

            Schedule(input, 1);
            Schedule(atmosphere, 1);
            Schedule(FCS, 1);
            Schedule(propulsion, 1);
            Schedule(massBalance, 1);
            Schedule(aerodynamics, 1);
            Schedule(inertial, 1);
            Schedule(groundReactions, 1);
            Schedule(aircraft, 1);
            Schedule(propagate, 1);
            Schedule(auxiliary, 1);
            //Schedule(output, 1);

            modelLoaded = false;
            return(result);
        }