public float Caculate(float minSliced, float maxSliced, GameObject gameObject) { float submergedVolume = 0.0f; float waterplaneArea = 0.0f; try { SliceMeshVol meshVolume = new SliceMeshVol(); GameObject[] result = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(maxSliced, false, false); GameObject[] result2 = result[1].AddComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(minSliced, false, false, result[1]); submergedVolume = meshVolume.VolumeOfMesh(result2[0].GetComponent <MeshFilter>().sharedMesh); waterplaneArea = submergedVolume / (maxSliced - minSliced); string msg = "Volume for draught : " + " is : " + submergedVolume + " cube units."; msg = "Waterplane area is : " + waterplaneArea + " sq units."; Debug.Log(msg); } catch (Exception ex) { Debug.Log("Exception : " + ex.ToString()); } return(waterplaneArea); }
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); }
public void SLiceIt() { var splitSize = 10f; GameObject[] result = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullHorizontal(.1f, true, true, null); GameObject upperHalfHull = result[0]; Mesh mesh = upperHalfHull.GetComponent <MeshFilter>().sharedMesh; var totalLength = Math.Abs(mesh.vertices.Min(x => x.x)) + Math.Abs(mesh.vertices.Max(x => x.x)); Debug.Log("WL Length : " + totalLength); float equalChunk = totalLength / splitSize; float currentLength = mesh.vertices.Min(x => x.x) + equalChunk; System.Collections.Generic.List <Tuple <float, float> > coordinates = new System.Collections.Generic.List <Tuple <float, float> >(); coordinates.Add(new Tuple <float, float>(mesh.vertices.Min(x => x.x), 5)); SliceMeshVol meshVolume = new SliceMeshVol(); //int totalFailures = 0; for (int i = 1; i <= splitSize; i++) { GameObject[] slicedHulls = null; if (currentLength >= 0) { slicedHulls = upperHalfHull.AddComponent <RuntimeShatterExample>().SlicedVerticalShipHull(currentLength, true, true, upperHalfHull); } else { slicedHulls = upperHalfHull.AddComponent <RuntimeShatterExample>().SlicedVerticalShipHull(currentLength, true, true, upperHalfHull); } if (slicedHulls != null) { float sliceY = 0.0f; Mesh meshed = null; if (currentLength == 0) { coordinates.Add(new Tuple <float, float>(currentLength, 5f)); } else { if (currentLength > 0) { meshed = slicedHulls[1].GetComponent <MeshFilter>().sharedMesh; } else { meshed = slicedHulls[0].GetComponent <MeshFilter>().sharedMesh; } if (meshed.vertices.Any(x => x.x == currentLength)) { sliceY = meshed.vertices.Where(x => x.x == currentLength).Max(z => z.y); } else { sliceY = coordinates[i - 1].Item2 + .00001f; } coordinates.Add(new Tuple <float, float>(currentLength, sliceY)); } } else { coordinates.Add(new Tuple <float, float>(currentLength, 5f)); } currentLength += equalChunk; } foreach (var item in coordinates) { Debug.Log("FOr x : " + item.Item1 + ", Y is : " + item.Item2); } SecondMomentOfInertia(coordinates, equalChunk); }
public void applySimpson(float addedMass, float totalDisplacement, float maxSlicedPoint, float minSlicedPoint, float locationAtX) { try { #region Working var maxSlicer = maxSlicedPoint; var minSlicer = minSlicedPoint; System.Collections.Generic.List <Tuple <float, float> > coordinates = new System.Collections.Generic.List <Tuple <float, float> >(); GameObject originalObject = gameObject; GameObject submergedHull1 = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(maxSlicer, false, false, null)[1]; // GetSubmergedHull(); GameObject submergedHull = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(minSlicer, false, false, submergedHull1)[0]; // GetSubmergedHull(); GameObject[] halfHull = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullHorizontal(0.005f, true, true, submergedHull); GameObject upperHalfHull = halfHull[0]; Mesh mesh = upperHalfHull.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); float equalChunk = waterplaneLength / splitSize; float currentLength = mesh.vertices.Min(x => x.x) + equalChunk; coordinates.Add(new Tuple <float, float>(mesh.vertices.Min(x => x.x), 0)); SliceMeshVol meshVolume = new SliceMeshVol(); GameObject subHull = gameObject.AddComponent <RuntimeShatterExample>().SlicedShipHullAlongZ(minSlicer, false, false)[1]; var currentSubmergedVolume = meshVolume.VolumeOfMesh(subHull.GetComponent <MeshFilter>().sharedMesh) / 1.025f; int totalFailures = 0; for (int i = 1; i <= splitSize; i++) { GameObject[] slicedHulls = null; if (currentLength > 0) { slicedHulls = upperHalfHull.AddComponent <RuntimeShatterExample>().SlicedVerticalShipHull(currentLength, false, false, upperHalfHull); } else { slicedHulls = upperHalfHull.AddComponent <RuntimeShatterExample>().SlicedVerticalShipHull(currentLength, false, false, upperHalfHull); } if (slicedHulls != null) { float sliceY = 0.0f; Mesh meshed = null; if (currentLength > 0) { meshed = slicedHulls[1].GetComponent <MeshFilter>().sharedMesh; } else { meshed = slicedHulls[0].GetComponent <MeshFilter>().sharedMesh; } if (meshed.vertices.Any(x => x.x == currentLength)) { sliceY = meshed.vertices.Where(x => x.x == currentLength).Max(z => z.y); } else { totalFailures++; sliceY = coordinates[i - 1].Item2 + .00001f; } coordinates.Add(new Tuple <float, float>(currentLength, sliceY)); } else { coordinates.Add(new Tuple <float, float>(currentLength, 3.889421f)); } currentLength += equalChunk; } // SecondMomentOfInertia(coordinates, equalChunk); //var area = CalculateArea(coordinates, equalChunk); #region Verified One var Ix = CalculateIX(coordinates, equalChunk); var gml = COF(coordinates, equalChunk, currentSubmergedVolume); #endregion #endregion CalculateWaterplaneArea wpArea = new CalculateWaterplaneArea(); var waterplaneArea = wpArea.Caculate(minSlicedPoint, maxSlicedPoint, originalObject); CalculateTrim(addedMass, totalDisplacement, locationAtX, waterplaneArea, waterplaneLength, gml); CalculateList(addedMass, totalDisplacement, Ix, CLPosition, gml, maxSlicedPoint, originalObject); } catch (Exception ex) { Debug.Log("Exception : " + ex.ToString()); } }
public void ApplySimpsonRule(float maxSlicedPoint, float minSlicedPoint, float locationAtX) { try { #region Working var maxSlicer = maxSlicedPoint; var minSlicer = minSlicedPoint; System.Collections.Generic.List <Tuple <float, float> > coordinates = new System.Collections.Generic.List <Tuple <float, float> >(); GameObject originalObject = OriginalGameObject; RuntimeShatterExample originalObjectComponent = originalObject.GetComponent <RuntimeShatterExample>(); GameObject submergedHullFromMaximumSlicingPoint = originalObjectComponent.SlicedShipHullAlongZ(maxSlicer, false, false, null)[1]; GameObject submergedHullFromMinimumSlicingPoint = originalObjectComponent.SlicedShipHullAlongZ(minSlicer, false, false, submergedHullFromMaximumSlicingPoint)[0]; GameObject[] halfHull = originalObjectComponent.SlicedShipHullHorizontal(AnonymousHullData.ShipHalfOrdinatePointForSimpsonRule, false, false, submergedHullFromMinimumSlicingPoint); GameObject upperHalfHull = halfHull[0]; Mesh mesh = upperHalfHull.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); float equalChunk = waterplaneLength / AnonymousHullData.SplitSize; float currentLength = mesh.vertices.Min(x => x.x) + equalChunk; coordinates.Add(new Tuple <float, float>(mesh.vertices.Min(x => x.x), 0)); SliceMeshVol meshVolume = new SliceMeshVol(); GameObject subHull = originalObjectComponent.SlicedShipHullAlongZ(minSlicer, false, false)[1]; var currentSubmergedVolume = meshVolume.VolumeOfMesh(subHull.GetComponent <MeshFilter>().sharedMesh) / AnonymousHullData.Density; int totalFailures = 0; upperHalfHull.AddComponent <RuntimeShatterExample>(); for (int i = 1; i <= AnonymousHullData.SplitSize; i++) { GameObject[] slicedHulls = null; if (currentLength > 0) { slicedHulls = upperHalfHull.GetComponent <RuntimeShatterExample>().SlicedVerticalShipHull(currentLength, false, false, upperHalfHull); } else { slicedHulls = upperHalfHull.GetComponent <RuntimeShatterExample>().SlicedVerticalShipHull(currentLength, false, false, upperHalfHull); } if (slicedHulls != null) { float sliceY = 0.0f; Mesh meshed = null; if (currentLength > 0) { meshed = slicedHulls[1].GetComponent <MeshFilter>().sharedMesh; } else { meshed = slicedHulls[0].GetComponent <MeshFilter>().sharedMesh; } if (meshed.vertices.Any(x => x.x == currentLength)) { sliceY = meshed.vertices.Where(x => x.x == currentLength).Max(z => z.y); } else { totalFailures++; sliceY = coordinates[i - 1].Item2 + .00001f; } coordinates.Add(new Tuple <float, float>(currentLength, sliceY)); } else { coordinates.Add(new Tuple <float, float>(currentLength, AnonymousHullData.HullFinalOrdinateHeight)); } currentLength += equalChunk; } #region Verified One var Ix = CalculateIX(coordinates, equalChunk); var gml = COF(coordinates, equalChunk, currentSubmergedVolume); #endregion #endregion CalculateWaterplaneArea wpArea = new CalculateWaterplaneArea(); var waterplaneArea = wpArea.Caculate(minSlicedPoint, maxSlicedPoint, originalObject); float CLPosition = -5f; CalculateTrim(InputData.Conditions.ElementAt(0).LoadAdded, InputData.InitialDisplacement + InputData.Conditions.ElementAt(0).LoadAdded, locationAtX, waterplaneArea, waterplaneLength, gml); CalculateList(InputData.Conditions.ElementAt(0).LoadAdded, InputData.InitialDisplacement + InputData.Conditions.ElementAt(0).LoadAdded, Ix, CLPosition, gml, maxSlicedPoint, originalObject); ShipHydrostaticData.WaterplaneLength = waterplaneLength; ShipHydrostaticData.MomentOfInertiaX = Ix; ShipHydrostaticData.GMl = gml; ShipHydrostaticData.WaterplaneArea = waterplaneArea; } catch (Exception ex) { Debug.Log("Exception : " + ex.ToString()); } }
/// <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); }