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);
        }
Exemple #2
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);
    }