예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        //Quaternion rotationX = Quaternion.AngleAxis(10, new Vector3(1f, 0f, 0f));
        //gameObject.transform.rotation = rotationX;

        gameObject.AddComponent <RuntimeShatterExample>();

        #region Comment
        //GameObject[] result = gameObject.AddComponent<RuntimeShatterExample>().SlicedShipHullAlongZ(1.417989f, true, true, null);
        //currentSubmergedVolume = meshVolume.VolumeOfMesh(result[0].GetComponent<MeshFilter>().sharedMesh) / density;

        //while (scale < 2f)
        //{
        //    GameObject[] result = gameObject.AddComponent<RuntimeShatterExample>().SlicedShipHullAlongZ(1.417989f, true, true, null);
        //    currentSubmergedVolume = meshVolume.VolumeOfMesh(result[0].GetComponent<MeshFilter>().sharedMesh) / density;

        //    string msg = "Volume for draught :   " + scale + " is : " + currentSubmergedVolume + " cube units.";
        //    Debug.Log(msg);

        //    previousScale = scale;
        //    scale += 0.002f;
        //}
        #endregion

        GameObject[] result = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullHorizontal(3.01f, true, true, null);

        var mesh = result[1].GetComponent <MeshFilter>().sharedMesh;

        //var waterplaneLength = Math.Abs(mesh.vertices.Min(x => x.x)) + Math.Abs(mesh.vertices.Max(x => x.x));
        //Debug.Log("WL Length  :  " + waterplaneLength);

        CalculateCentroidFromVolume centroidFromVol = new CalculateCentroidFromVolume();
        centroidFromVol.CalculateLCB(mesh);
        centroidFromVol.VolumeOfMesh(mesh);
    }
        public Tuple <float, float> CalculateBuoyancy(float volume, float inScale)
        {
            Tuple <float, float> returnValue   = new Tuple <float, float>(0, 0);
            GameObject           submergedHull = null;

            try
            {
                float density = 1.025f;

                float exactSubmergedVolume = volume;
                float scale = inScale;

                float currentSubmergedVolume = 0.0f;

                SliceMeshVol meshVolume = new SliceMeshVol();

                float previousScale = 0.0f;

                while (currentSubmergedVolume < exactSubmergedVolume && scale < 5.0f)
                {
                    GameObject[] result = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(scale, false, false, null);
                    currentSubmergedVolume = meshVolume.VolumeOfMesh(result[1].GetComponent <MeshFilter>().sharedMesh) / density;

                    submergedHull = result[1];

                    string msg = "Volume for draught :   " + scale + " is : " + currentSubmergedVolume + " cube units.";
                    Debug.Log(msg);

                    previousScale = scale;
                    scale        += 0.002f;
                }

                returnValue = new Tuple <float, float>(previousScale, scale);

                Debug.Log("Total Displacement : " + (exactSubmergedVolume * 1.025f));
                Debug.Log("Volume : " + currentSubmergedVolume);
                Debug.Log("Draft Amidships : " + scale);
                Debug.Log("Immersed Depth : " + scale);

                var wettedHull = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(scale, true, true, null);

                CalculateCentroidFromArea centroidFromArea = new CalculateCentroidFromArea();
                var wettedArea = centroidFromArea.AreaOfMesh(wettedHull[1].GetComponent <MeshFilter>().sharedMesh);

                Debug.Log("Area is : " + wettedArea);

                CalculateCentroidFromVolume centroidFromVol = new CalculateCentroidFromVolume();

                centroidFromVol.CalculateKB(wettedHull[1].GetComponent <MeshFilter>().sharedMesh);
                centroidFromVol.CalculateLCB(wettedHull[1].GetComponent <MeshFilter>().sharedMesh);
            }
            catch (Exception ex)
            {
                Debug.Log(ex.ToString());
            }

            return(returnValue);
        }
예제 #3
0
    public void CalculateList(float addedMass, float totalDisplacement, float MomentOfInertiaIx, float CLPosition, float gml, float maxSlice, GameObject gameObject)
    {
        float FixedKG  = 3.5f;
        float KgZValue = 0.0f;

        float BMt = MomentOfInertiaIx / totalDisplacement;
        //Debug.Log("BMt is : " + BMt);

        CalculateCentroidFromVolume centroidFromVolume = new CalculateCentroidFromVolume();

        GameObject[] result = gameObject.GetComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(maxSlice, false, false, null);
        var          KB     = centroidFromVolume.CalculateKB(result[1].GetComponent <MeshFilter>().sharedMesh);
        //Debug.Log("KB is : " + KB);

        var KM = KB + BMt;
        //Debug.Log("KM is : " + KM);

        var initialDisplacement = totalDisplacement - addedMass;

        var overallKG = ((initialDisplacement * FixedKG) + (addedMass * KgZValue)) / totalDisplacement;
        //Debug.Log("Overall KG is : " + overallKG);

        var GM = KM - overallKG;
        // Debug.Log("GM is : " + GM);

        var moment = addedMass * CLPosition;
        // Debug.Log("moment is : " + moment);

        var ListAngle = moment / (totalDisplacement * GM);

        // Debug.Log("List Angle is : " + ListAngle);


        ShipHydrostaticData.BMt    = BMt;
        ShipHydrostaticData.Km     = KM;
        ShipHydrostaticData.KG     = overallKG;
        ShipHydrostaticData.GM     = GM;
        ShipHydrostaticData.Moment = moment;
        ShipHydrostaticData.List   = ListAngle;
    }
예제 #4
0
    /// <summary>
    ///  Returns Maximum and Minimum Scale
    /// </summary>
    /// <param name="totalLoad"></param>
    /// <param name="inScale"></param>
    /// <param name="inDensity"></param>
    /// <param name="maxScale"></param>
    /// <param name="incrementInScale"></param>
    /// <returns></returns>
    public Tuple <float, float> CalculateDraught(float totalLoad, float inScale, float inDensity, float maxScale, float incrementInScale)
    {
        Tuple <float, float> returnValue = new Tuple <float, float>(0, 0);

        try
        {
            #region Declaration

            GameObject   submergedHull        = null;
            float        density              = inDensity;
            float        exactSubmergedVolume = totalLoad / density;
            float        scale = inScale;
            float        currentSubmergedVolume = 0.0f;
            SliceMeshVol meshVolume             = new SliceMeshVol();
            float        previousScale          = 0.0f;

            #endregion

            gameObject.AddComponent <RuntimeShatterExample>();
            var runtimeShatterComponent = gameObject.GetComponent <RuntimeShatterExample>();

            while (currentSubmergedVolume < exactSubmergedVolume && scale < maxScale)
            {
                GameObject[] result = runtimeShatterComponent.SlicedShipHullAlongZ(scale, false, false, null);
                currentSubmergedVolume = meshVolume.VolumeOfMesh(result[1].GetComponent <MeshFilter>().sharedMesh) / density;

                submergedHull = result[1];

                previousScale = scale;
                scale        += incrementInScale;
            }

            returnValue = new Tuple <float, float>(previousScale, scale);

            //Debug.Log("Total Displacement : " + (exactSubmergedVolume * density));
            //Debug.Log("Volume : " + currentSubmergedVolume);
            //Debug.Log("Draft Amidships : " + scale);
            //Debug.Log("Immersed Depth : " + scale);

            var wettedHull = runtimeShatterComponent.SlicedShipHullAlongZ(scale, true, true, null);

            #region Caution
            /// Need to review area script
            CalculateCentroidFromArea centroidFromArea = new CalculateCentroidFromArea();
            var wettedArea = centroidFromArea.AreaOfMesh(wettedHull[1].GetComponent <MeshFilter>().sharedMesh);
            // Debug.Log("Area is : " + wettedArea);
            #endregion

            CalculateCentroidFromVolume centroidFromVol = new CalculateCentroidFromVolume();

            var kb  = centroidFromVol.CalculateKB(wettedHull[1].GetComponent <MeshFilter>().sharedMesh);
            var lcb = centroidFromVol.CalculateLCB(wettedHull[1].GetComponent <MeshFilter>().sharedMesh);


            ShipHydrostaticData.Draught       = scale;
            ShipHydrostaticData.ImmersedDepth = scale;
            ShipHydrostaticData.Volume        = currentSubmergedVolume;
            ShipHydrostaticData.Displacement  = totalLoad;
            ShipHydrostaticData.KB            = kb;
            ShipHydrostaticData.LCBLength     = lcb;
        }
        catch (Exception ex)
        {
            Debug.Log("CalculateDraught :: Exception : " + ex.ToString());
        }

        return(returnValue);
    }